abseil / abseil-cpp

Abseil Common Libraries (C++)
https://abseil.io
Apache License 2.0
15.05k stars 2.62k forks source link

Build error using CMake at macOS Sierra #375

Open henryly94 opened 5 years ago

henryly94 commented 5 years ago

Here's the build log:

[ 35%] Building CXX object absl/time/CMakeFiles/time_zone.dir/internal/cctz/src/time_zone_format.cc.o
In file included from /Users/lyy/workspace/C++/abseil-cpp/absl/time/internal/cctz/src/time_zone_format.cc:27:
In file included from /Users/lyy/workspace/C++/abseil-cpp/absl/time/internal/cctz/include/cctz/time_zone.h:28:
In file included from /Users/lyy/workspace/C++/abseil-cpp/absl/time/internal/cctz/include/cctz/civil_time.h:18:
In file included from /Users/lyy/workspace/C++/abseil-cpp/absl/time/internal/cctz/include/cctz/civil_time_detail.h:20:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/ostream:138:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/ios:216:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/__locale:18:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/mutex:189:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/__mutex_base:17:
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/__threading_support:156:1: error: unknown
      type name 'mach_port_t'
mach_port_t __libcpp_thread_get_port();
^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/__threading_support:300:1: error: unknown
      type name 'mach_port_t'
mach_port_t __libcpp_thread_get_port() {
^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/__threading_support:301:12: error: use of
      undeclared identifier 'pthread_mach_thread_np'
    return pthread_mach_thread_np(pthread_self());
           ^
3 errors generated.
make[2]: *** [absl/time/CMakeFiles/time_zone.dir/internal/cctz/src/time_zone_format.cc.o] Error 1
make[1]: *** [absl/time/CMakeFiles/time_zone.dir/all] Error 2
make: *** [all] Error 2

Saw similar issue elsewhere: https://github.com/tensorflow/tensorflow/issues/13220

rogeeff commented 5 years ago

We'll try to reproduce, but the build log as well as the issue you are referencing makes me doubt this is an issue with Abseil code. Maybe we can work around it. Do you have any suggestions?

henryly94 commented 5 years ago

We'll try to reproduce, but the build log as well as the issue you are referencing makes me doubt this is an issue with Abseil code. Maybe we can work around it. Do you have any suggestions?

I tried the same process on macOS High Sierra and the build success. I suspect it is something related to Sierra. The link here(https://github.com/tensorflow/tensorflow/issues/13220) suggest a workaround that defining some macros in certain file.

Add this macro:

#ifdef __APPLE__ 
#define _DARWIN_C_SOURCE 
#endif

to the beginning of this header file: absl/time/internal/cctz/include/cctz/civil_time_detail.h

bluescarni commented 5 years ago

We are seeing the same issue when building abesil-cpp with clang 4 on OSX. Building with clang 8 does not exhibit the problem. The patch proposed by @henryly94 does fix the build in our case.