Hello, I have been trying to follow a online tutorial for C++ pthread and I cannot seem to get pthread to link with cmake and clang. I have been tried four different solutions that I found on other forums but none seem to work.
cmake_minimum_required(VERSION 2.6)
SET (CMAKE_C_COMPILER "/usr/bin/clang")
SET (CMAKE_C_FLAGS "-Wall -std=c++11 -Werror")
SET (CMAKE_C_FLAGS_DEBUG "-g")
SET (CMAKE_C_FLAGS_MINSIZEREL "-Os -DNDEBUG")
SET (CMAKE_C_FLAGS_RELEASE "-O4 -DNDEBUG")
SET (CMAKE_C_FLAGS_RELWITHDEBINFO "-O2 -g")
SET (CMAKE_CXX_COMPILER "/usr/bin/clang++")
SET (CMAKE_CXX_FLAGS "-Wall -std=c++11 -Werror")
SET (CMAKE_CXX_FLAGS_DEBUG "-g")
SET (CMAKE_CXX_FLAGS_MINSIZEREL "-Os -DNDEBUG")
SET (CMAKE_CXX_FLAGS_RELEASE "-O4 -DNDEBUG")
SET (CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O2 -g")
SET (CMAKE_AR "/usr/bin/llvm-ar")
SET (CMAKE_LINKER "/usr/bin/llvm-ld")
SET (CMAKE_NM "/usr/bin/llvm-nm")
SET (CMAKE_OBJDUMP "/usr/bin/llvm-objdump")
SET (CMAKE_RANLIB "/usr/bin/llvm-ranlib")
SET (LLVM_ENABLE_THREADS "yes")
project(threading)
add_executable(threading main.cpp)
TARGET_LINK_LIBRARIES(pthread)
Thanks
Sorry here is the error:
1 2 3 4 5 6 7 8 9
CMakeFiles/threading.dir/main.cpp.o: In function `main':
/home/arortell/Development/Projects/C++_Projects/Threading/main.cpp:18: undefined reference to `pthread_create'
x86_64-pc-linux-gnu-clang-3.5.0: error: linker command failed with exit code 1 (use -v to see invocation)
CMakeFiles/threading.dir/build.make:88: recipe for target 'threading' failed
make[2]: *** [threading] Error 1
CMakeFiles/Makefile2:63: recipe for target 'CMakeFiles/threading.dir/all' failed
make[1]: *** [CMakeFiles/threading.dir/all] Error 2
Makefile:75: recipe for target 'all' failed
make: *** [all] Error 2