I am using CMake 3.7.2 and playing around with the FindThread finder. The following simple CMakeLists.txt works fine on various compilers: GCC, clang, MSVC (tried 2013 and 2015).
CMAKE_MINIMUM_REQUIRED( VERSION 3.1 ) ADD_EXECUTABLE( mythread main.cpp ) SET( THREADS_PREFER_PTHREAD_FLAG TRUE ) FIND_PACKAGE( Threads REQUIRED ) TARGET_LINK_LIBRARIES( thread Threads::Threads ) TARGET_COMPILE_OPTIONS( thread INTERFACE Threads::Threads ) However, when I attempt to cross-compile for ARM with "cmake -DCMAKE_TOOLCHAIN_FILE=blah ..", I get the following: -- The C compiler identification is GNU 4.9.4 -- The CXX compiler identification is GNU 4.9.4 -- Check for working C compiler: /usr/bin/armv6j-hardfloat-linux-gnueabi-gcc-4.9.4 -- Check for working C compiler: /usr/bin/armv6j-hardfloat-linux-gnueabi-gcc-4.9.4 -- works -- Detecting C compiler ABI info -- Detecting C compiler ABI info - done -- Detecting C compile features -- Detecting C compile features - done -- Check for working CXX compiler: /usr/bin/armv6j-hardfloat-linux-gnueabi-g++-4.9.4 -- Check for working CXX compiler: /usr/bin/armv6j-hardfloat-linux-gnueabi-g++-4.9.4 -- works -- Detecting CXX compiler ABI info -- Detecting CXX compiler ABI info - done -- Detecting CXX compile features -- Detecting CXX compile features - done -- Looking for pthread.h -- Looking for pthread.h - found -- Looking for pthread_create -- Looking for pthread_create - not found -- Check if compiler accepts -pthread CMake Error: TRY_RUN() invoked in cross-compiling mode, please set the following cache variables appropriately: THREADS_PTHREAD_ARG (advanced) For details see /tmp/thread/build/TryRunResults.cmake -- Check if compiler accepts -pthread - no -- Found Threads: TRUE -- Configuring incomplete, errors occurred! See also "/tmp/thread/build/CMakeFiles/CMakeOutput.log". See also "/tmp/thread/build/CMakeFiles/CMakeError.log". I can verify that the compiler does indeed accept -pthread, and IIRC might require it for pthreads to work. I can see from the CMakeError.log that it might be forgetting to specify -lpthread when trying to compile the test: Run Build Command:"/usr/bin/gmake" "cmTC_13694/fast" /usr/bin/gmake -f CMakeFiles/cmTC_13694.dir/build.make CMakeFiles/cmTC_13694.dir/build gmake[1]: Entering directory '/tmp/thread/build/CMakeFiles/CMakeTmp' Building C object CMakeFiles/cmTC_13694.dir/CheckSymbolExists.c.o /usr/bin/armv6j-hardfloat-linux-gnueabi-gcc-4.9.4 --sysroot=/mnt/data/chroots/pie/ -o CMakeFiles/cmTC_13694.dir/CheckSymbolExists.c.o -c /tmp/thread/build/CMakeFiles/CMakeTmp/CheckSymbolExists.c Linking C executable cmTC_13694 /usr/bin/cmake -E cmake_link_script CMakeFiles/cmTC_13694.dir/link.txt --verbose=1 /usr/bin/armv6j-hardfloat-linux-gnueabi-gcc-4.9.4 --sysroot=/mnt/data/chroots/pie/ CMakeFiles/cmTC_13694.dir/CheckSymbolExists.c.o -o cmTC_13694 -rdynamic CMakeFiles/cmTC_13694.dir/CheckSymbolExists.c.o: In function `main': CheckSymbolExists.c:(.text+0x38): undefined reference to `pthread_create' collect2: error: ld returned 1 exit status gmake[1]: *** [CMakeFiles/cmTC_13694.dir/build.make:98: cmTC_13694] Error 1 gmake[1]: Leaving directory '/tmp/thread/build/CMakeFiles/CMakeTmp' gmake: *** [Makefile:126: cmTC_13694/fast] Error 2 File /tmp/thread/build/CMakeFiles/CMakeTmp/CheckSymbolExists.c: /* */ #include <pthread.h> int main(int argc, char** argv) { (void)argv; #ifndef pthread_create return ((int*)(&pthread_create))[argc]; #else (void)argc; return 0; #endif } Is this a bug? Or am I not using the find correctly?
-- Powered by www.kitware.com Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ Kitware offers various services to support the CMake community. For more information on each offering, please visit: CMake Support: http://cmake.org/cmake/help/support.html CMake Consulting: http://cmake.org/cmake/help/consulting.html CMake Training Courses: http://cmake.org/cmake/help/training.html Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html Follow this link to subscribe/unsubscribe: http://public.kitware.com/mailman/listinfo/cmake