Darwin (MacOS) build error with Xcode 9
Compiling Charm++ with Xcode 9 results in a build failure, due to changes in header files.
Other projects (example from TensorFlow: https://github.com/tensorflow/tensorflow/issues/13220#issuecomment-331579775) have had the same issue.
The internal C++
__threading_support header (
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/__threading_support) defines the
__libcpp_thread_get_port() function, which internally uses
That function is defined in
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/pthread.h), but the function is hidden behind preprocessor conditions:
#if (!defined(_POSIX_C_SOURCE) && !defined(_XOPEN_SOURCE)) || defined(_DARWIN_C_SOURCE) || defined(__cplusplus)
_XOPEN_SOURCEis defined in
src/arch/*-darwin-x86_64/conv-mach.hso that the
ucontextfunctions can be used.
A workaround is to also define
_DARWIN_C_SOURCE. I have no idea why
Another option is to use
<sys/ucontext.h> instead of
<ucontext.h>, which I don't think has the same requirement for
#3 Updated by Evan Ramos about 2 months ago
My patch uses the _DARWIN_C_SOURCE workaround, which is what I found used by two open source projects that came up in search results for the error message. It mitigates the issue entirely with no side effects I have observed, but it still feels like a hack.
#5 Updated by Evan Ramos about 2 months ago
Other projects with the same problem and solution: