Bug #1743

Darwin (MacOS) build error with Xcode 9

Added by Omri Mor about 1 year ago. Updated 12 months ago.

Machine Layers
Target version:
Start date:
Due date:
% Done:



Compiling Charm++ with Xcode 9 results in a build failure, due to changes in header files.
Other projects (example from TensorFlow: have had the same issue.
The internal C++ __threading_support header (/Applications/ defines the __libcpp_thread_get_port() function, which internally uses pthread_mach_thread_np().
That function is defined in pthread.h (/Applications/, but the function is hidden behind preprocessor conditions:

#if (!defined(_POSIX_C_SOURCE) && !defined(_XOPEN_SOURCE)) || defined(_DARWIN_C_SOURCE) || defined(__cplusplus)
_XOPEN_SOURCE is defined in src/arch/*-darwin-x86_64/conv-mach.h so that the ucontext functions can be used.
A workaround is to also define _POSIX_C_SOURCE or _DARWIN_C_SOURCE. I have no idea why __cplusplus isn't defined.

Another option is to use <sys/ucontext.h> instead of <ucontext.h>, which I don't think has the same requirement for _XOPEN_SOURCE

Related issues

Related to Charm++ - Bug #1728: Darwin clang compilation fails without -D_DARWIN_C_SOURCE on Sierra Rejected 10/30/2017


#1 Updated by Sam White about 1 year ago

  • Target version set to 6.9.0

#2 Updated by Sam White 12 months ago

  • Assignee set to Evan Ramos
  • Status changed from New to In Progress

#3 Updated by Evan Ramos 12 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.

#4 Updated by Evan Ramos 12 months ago

  • Related to Bug #1728: Darwin clang compilation fails without -D_DARWIN_C_SOURCE on Sierra added

#6 Updated by Evan Ramos 12 months ago

  • Status changed from In Progress to Merged

Also available in: Atom PDF