Compiling C Code with Conflicting Types

I am coding a program that uses ossp-uuid which defines a type called uuid_t. Now the problem is that this type is already defined on Mac OSX in the unistd.h file.

So I am getting the error:

/opt/local/include/ossp/uuid.h:94: error: conflicting types for 'uuid_t'
/usr/include/unistd.h:133: error: previous declaration of 'uuid_t' was here

      

I complicate my program:

gcc -DPACKAGE_NAME=\"\" -DPACKAGE_TARNAME=\"\" -DPACKAGE_VERSION=\"\" - 
DPACKAGE_STRING=\"\" -DPACKAGE_BUGREPORT=\"\" -DPACKAGE_URL=\"\" 
-DPACKAGE=\"epride\" -DVERSION=\"0.2\" -I.    -I/usr/local/BerkeleyDB.4.7/include 
-I/opt/local/include -I/opt/local/include/db47 -I/opt/local/include/libxml2 
`pkg-config --cflags glib-2.0` -DNUM_REPLICAS=1 -DGEN_SIZE=10 -g -O2 -MT 
libepride_a-conflictset.o -MD -MP -MF .deps/libepride_a-conflictset.Tpo
-c -o libepride_a-conflictset.o `test -f 'conflictset.c' 
|| echo './'`conflictset.c

      

Is there a way to tell gcc to ignore the type from unistd.h? Because I am using unistd.h for other things.

Uuid.h has the following lines:

/* workaround conflicts with system headers */
#define uuid_t       __vendor_uuid_t
#define uuid_create  __vendor_uuid_create
#define uuid_compare __vendor_uuid_compare
#include <sys/types.h>
#include <unistd.h>
#undef  uuid_t
#undef  uuid_create
#undef  uuid_compare

      

Wouldn't that take care of this?

Thanks in advance!

+2


source to share


4 answers


You should check /opt/local/include/ossp/uuid.h on line 94 and hope there is a definition for uuid_t. Hope you find something like:

#ifndef UUID_T_DEFINED
#define UUID_T_DEFINED
typedef uuid_t .... whatever
#endif

      

If the guys who wrote this title did it this way, you can change your code:



#include <unistd.h>
#define UUID_T_DEFINED
#include <ossp/uuid.h>

      

Thus, it will not be the second #include in the uuid_t declaration in ossp / uuid.h.

+2


source


Something like that?

#define uuid_t unistd_uuid_t
#include <unistd.h>
#undef uuid_t
#include <ossp/uuid.h> /* or whatever header you're including */

      



It's ugly, but okay, it's C ...

+2


source


If you have access to the source code of the ossp-uuid library, you can rename the offending identifier to something like ossp_uuid_t with a simple text search and replace. Recompile and reinstall the library and you should be fine.

+1


source


This may be more complicated than you need, but one of them is to wrap ossp-uuid in a shared library and create an API that doesn't expose the underlying type uuid_t

.

0


source







All Articles