-
Notifications
You must be signed in to change notification settings - Fork 6.6k
Open
Description
Hello!
When trying to build rocksdb 10.5.1 on my Mac M1, using AppleClang as compiler and using external Folly, CMake fails when trying to find Thread with the following error:
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Failed
-- Looking for pthread_create in pthreads
-- Looking for pthread_create in pthreads - not found
-- Looking for pthread_create in pthread
-- Looking for pthread_create in pthread - not found
-- Check if compiler accepts -pthread
-- Check if compiler accepts -pthread - no
CMake Error at /opt/homebrew/share/cmake/Modules/FindPackageHandleStandardArgs.cmake:227 (message):
Could NOT find Threads (missing: Threads_FOUND)
Call Stack (most recent call first):
/opt/homebrew/share/cmake/Modules/FindPackageHandleStandardArgs.cmake:591 (_FPHSA_FAILURE_MESSAGE)
/opt/homebrew/share/cmake/Modules/FindThreads.cmake:226 (find_package_handle_standard_args)
CMakeLists.txt:634 (find_package)
-- Configuring incomplete, errors occurred!
Reading the CMake configure log to obtain a more detailed output I can see:
-
kind: "try_compile-v1"
backtrace:
- "/opt/homebrew/share/cmake/Modules/FindThreads.cmake:136 (try_compile)"
- "/opt/homebrew/share/cmake/Modules/FindThreads.cmake:179 (_threads_check_flag_pthread)"
- "CMakeLists.txt:634 (find_package)"
checks:
- "Check if compiler accepts -pthread"
directories:
source: "/Users/uilian/.conan2/p/b/rocksde5d29833fc26/b/build/Release/CMakeFiles/CMakeScratch/TryCompile-gVC6Sc"
binary: "/Users/uilian/.conan2/p/b/rocksde5d29833fc26/b/build/Release/CMakeFiles/CMakeScratch/TryCompile-gVC6Sc"
cmakeVariables:
CMAKE_C_FLAGS: " -march=armv8-a+crc+crypto -Wno-unused-function"
CMAKE_C_FLAGS_DEBUG: "-g"
CMAKE_EXE_LINKER_FLAGS: " -Wl,--copy-dt-needed-entries"
CMAKE_MODULE_PATH: "/Users/uilian/.conan2/p/b/opens21f4e935f46db/p/lib/cmake;/Users/uilian/.conan2/p/b/rocksde5d29833fc26/b/build/Release/generators;/Users/uilian/.conan2/p/b/opens21f4e935f46db/p/lib/cmake;/Users/uilian/.conan2/p/b/rocksde
5d29833fc26/b/src/cmake/modules/"
CMAKE_OSX_ARCHITECTURES: "arm64"
CMAKE_OSX_DEPLOYMENT_TARGET: ""
CMAKE_OSX_SYSROOT: "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX15.5.sdk"
CMAKE_POSITION_INDEPENDENT_CODE: "ON"
buildResult:
variable: "THREADS_HAVE_PTHREAD_ARG"
cached: true
stdout: |
Change Dir: '/Users/uilian/.conan2/p/b/rocksde5d29833fc26/b/build/Release/CMakeFiles/CMakeScratch/TryCompile-gVC6Sc'
Run Build Command(s): /opt/homebrew/bin/ninja -v cmTC_a6c38
[1/2] /usr/bin/cc -march=armv8-a+crc+crypto -Wno-unused-function -arch arm64 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX15.5.sdk -fPIE -MD -MT CMakeFiles/cmTC_a6c38.dir/CheckFor
Pthreads.c.o -MF CMakeFiles/cmTC_a6c38.dir/CheckForPthreads.c.o.d -o CMakeFiles/cmTC_a6c38.dir/CheckForPthreads.c.o -c /Users/uilian/.conan2/p/b/rocksde5d29833fc26/b/build/Release/CMakeFiles/CMakeScratch/TryCompile-gVC6Sc/CheckForPthreads.c
[2/2] : && /usr/bin/cc -march=armv8-a+crc+crypto -Wno-unused-function -arch arm64 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX15.5.sdk -Wl,-search_paths_first -Wl,-headerpad_max_in
stall_names -Wl,--copy-dt-needed-entries CMakeFiles/cmTC_a6c38.dir/CheckForPthreads.c.o -o cmTC_a6c38 -pthread && :
FAILED: [code=1] cmTC_a6c38
: && /usr/bin/cc -march=armv8-a+crc+crypto -Wno-unused-function -arch arm64 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX15.5.sdk -Wl,-search_paths_first -Wl,-headerpad_max_install_
names -Wl,--copy-dt-needed-entries CMakeFiles/cmTC_a6c38.dir/CheckForPthreads.c.o -o cmTC_a6c38 -pthread && :
ld: unknown options: --copy-dt-needed-entries
clang: error: linker command failed with exit code 1 (use -v to see invocation)
ninja: build stopped: subcommand failed.
exitCode: 1
-
The error is caused because Clang does not support **--copy-dt-needed-entries **, but GCC supports it.
The following logic is listed here:
https://github.com/facebook/rocksdb/blob/v10.5.1/CMakeLists.txt#L637
Using the following patch should mitigate the current error:
diff --git a/CMakeLists.txt b/CMakeLists.txt
index ef93aa2..713d4c1 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -634,7 +634,9 @@ if(USE_FOLLY)
add_compile_definitions(USE_FOLLY FOLLY_NO_CONFIG HAVE_CXX11_ATOMIC)
list(APPEND THIRDPARTY_LIBS Folly::folly)
set(FOLLY_LIBS Folly::folly)
- set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--copy-dt-needed-entries")
+ if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
+ set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--copy-dt-needed-entries")
+ endif()
endif()
find_package(Threads REQUIRED)
Regards!
Metadata
Metadata
Assignees
Labels
No labels