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?
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__)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With