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

I support a mixed C and C ++ command-line program that should run on Linux, Windows, and OS X. I recently upgraded to Yosemite and my OS X build now fails. Error:

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

Other people have encountered this error .

The failed code line is a typedef that uses "^", which is a non-standard extension that provides support for closures .

The main problem is that some standard Apple headers are starting to require a Clang extension. Unfortunately, our program has a very deep set of dependencies, some of which will not compile under Clang. We used GCC compilers installed through MacPorts. I have a workaround: changing the line in the object.h header for GCC compatibility. However, hacking the included files under /usr/include sounds to me like asking for problems.

Can any OS X / Clang guru offer more sustainable ways to solve this problem? Does this limit the future usefulness of GCC on OS X?

+5
source share
1 answer

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

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

+13
source

Source: https://habr.com/ru/post/1211214/


All Articles