tags:

views:

345

answers:

4

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

So, the error I get is:

/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 complile my program with:

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 that he should ignore the type from unistd.h? Because I'm using unistd.h for other things.

In uuid.h there is these 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

Shouldn't that take care of it?

Thanks in advance!

+2  A: 

Something like this?

#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 well, it's C...

Thomas
+1  A: 

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

Tadeusz A. Kadłubowski
+2  A: 

You should check /opt/local/include/ossp/uuid.h at line 94 and hope that there's a define for uuid_t. Hopefully you'll find something like:

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

If the guys who wrote that header did it in this way, then you can modify your code:

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

This way, he second #include won't hit the declaration of uuid_t in ossp/uuid.h.

Karel Kubat
Good point. Try this before trying my suggestion.
Thomas
I only found:/* UUID abstract data type */struct uuid_st;typedef struct uuid_st uuid_t;
DeeD
You should check unistd.h as well.
jbcreix
@jbcreix Ah, found something interesting in unistd.h.
DeeD
A: 

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

Kristopher Johnson