Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to cope with non-gcc compatible code in OS X Yosemite Core headers

I maintain a mixed C and C++ command line program that needs to run on Linux, Windows, and OS X. I recently upgraded to Yosemite and my OS X build is now failing. The error is:

/usr/include/dispatch/object.h:143:15: error: expected identifier or '(' before '^' token

Other folks have run into this bug.

The line of code that fails is a typedef that uses '^' which is a non-standard extension providing support for closures.

The underlying problem seems to be that some Apple standard headers are starting to require Clang specific extensions. Unfortunately our program has a very deep set of dependencies, some of which won't compile under Clang. We've been using the GCC compilers installed via MacPorts. I have a workaround for now: changing the line in the object.h header to be GCC compatible. However, hacking up the include files under /usr/include sounds to me like asking for trouble.

Can any OS X/Clang gurus suggest more sustainable ways of coping with this problem? Does this limit the future usefulness of GCC on OS X?

like image 416
Charles E. Grant Avatar asked Jan 16 '15 02:01

Charles E. Grant


1 Answers

Just for future visitors, the following should get most headers working with a recent GCC version:

In dispatch/object.h change

typedef void (^dispatch_block_t)(void);

to

#ifdef __clang__
typedef void (^dispatch_block_t)(void);
#else
typedef void* dispatch_block_t;
#endif

and in Availability.h change

#elif defined(__MAC_OS_X_VERSION_MIN_REQUIRED)

to

#elif defined(__MAC_OS_X_VERSION_MIN_REQUIRED) && defined(__clang__)

like image 92
Thomas Avatar answered Oct 04 '22 04:10

Thomas