Issue
Here is my CMakeLists.txt:
if(WIN32)
if(MSVC)
list(APPEND PRIVATE_SOURCES AuthServer.rc)
endif()
endif()
add_executable(AuthServer
AuthServer.cpp
${PRIVATE_SOURCES}
../Database/Implementation/LoginDatabase.cpp
../Database/Implementation/LoginDatabase.h
../Database/Implementation/LoginDatabase/Accounts.h
../Database/Implementation/LoginDatabase/AccountRoles.h
../Database/Implementation/LoginDatabase/Accounts.cpp ../Database/Implementation/LoginDatabase/AccountRoles.cpp ../Memory/LoginMemory.h ../Memory/LoginMemory.cpp)
target_include_directories(AuthServer PUBLIC ../Database ../Database/Implementation/LoginDatabase/)
target_link_libraries(AuthServer LINK_PUBLIC Common)
if(NOT EXISTS ${CMAKE_BINARY_DIR}/bin/configs/)
message(STATUS "Configs folder will be created: ${CMAKE_BINARY_DIR}/bin/configs")
file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/bin/configs/)
endif()
if(NOT EXISTS ${CMAKE_BINARY_DIR}/bin/configs/AuthServer.conf)
message(STATUS "New AuthServer Config file in will be installed in: ${CMAKE_BINARY_DIR}/bin/configs")
add_custom_command(
TARGET AuthServer POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy
${CMAKE_CURRENT_SOURCE_DIR}/AuthServer.conf.dist
${CMAKE_BINARY_DIR}/bin/configs/AuthServer.conf)
endif()
When I try to build I receive an error in the linking stage:
[ 75%] Linking CXX executable ../../../bin/AuthServer
/usr/bin/ld: CMakeFiles/AuthServer.dir/AuthServer.cpp.o: undefined reference to symbol 'pthread_condattr_setclock@@GLIBC_2.3.3'
//lib/x86_64-linux-gnu/libpthread.so.0: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status
Source/Core/AuthServer/CMakeFiles/AuthServer.dir/build.make:165: recipe for target 'bin/AuthServer' failed
make[3]: *** [bin/AuthServer] Error 1
CMakeFiles/Makefile2:288: recipe for target 'Source/Core/AuthServer/CMakeFiles/AuthServer.dir/all' failed
make[2]: *** [Source/Core/AuthServer/CMakeFiles/AuthServer.dir/all] Error 2
CMakeFiles/Makefile2:295: recipe for target 'Source/Core/AuthServer/CMakeFiles/AuthServer.dir/rule' failed
make[1]: *** [Source/Core/AuthServer/CMakeFiles/AuthServer.dir/rule] Error 2
Makefile:210: recipe for target 'AuthServer' failed
make: *** [AuthServer] Error 2
I've made a research and it seems that I have to add lpthread
this to the command line of gcc. How can I achieve that in CMakeLists ?
Solution
Maybe something like :
target_link_libraries(
AuthServer
pthread
)
?
Answered By - Goozzi