简体   繁体   中英

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?

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__)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM