The error message means that you have to add pthread
to the list of linked libraries. In target_link_libraries
you only list the library names without path, lib
prefix and file extension:
cmake_minimum_required(VERSION 3.5)
set(CMAKE_CXX_STANDARD 11)
project(test C CXX)
find_package(Threads REQUIRED)
add_executable(${PROJECT_NAME} main.cpp)
target_include_directories(${PROJECT_NAME} PUBLIC ${CMAKE_SOURCE_DIR}/lib)
target_link_libraries(test A B Threads::Threads)
You can add paths with target_link_directories
:
cmake_minimum_required(VERSION 3.5)
set(CMAKE_CXX_STANDARD 11)
project(test C CXX)
find_package(ThreadsREQUIRED)
add_executable(${PROJECT_NAME} main.cpp)
target_include_directories(${PROJECT_NAME} PUBLIC ${CMAKE_SOURCE_DIR}/lib)
target_link_directories(test PRIVATE ${CMAKE_SOURCE_DIR})
target_link_libraries(test PRIVATE A B Threads::Threads)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…