I'm trying to compile the project with the structure:
-project
|-CMakeLists.txt (will call it the first CMakeLists later)
|-build
|-some files here
|-src
|-main.cpp
|-my_lib.h
|-my_lib.cpp
|-CMakeLists.txt (will call it the second CMakeLists later)
|-lib
|-third_party_lib.so
|-dep
|-third_party_lib
|-few .h files here
|-CMakeLists.txt (will call it the third CMakeLists later)
For compiling I'm going to build folder and do cmake ..
and cmake --build .
But I get errors:
/usr/bin/ld: ../lib/third_party_lib.so: undefined reference to `pthread_key_create@GLIBC_2.34'
/usr/bin/ld: ../lib/third_party_lib.so: undefined reference to `pthread_setspecific@GLIBC_2.34'
/usr/bin/ld: ../lib/third_party_lib.so: undefined reference to `__libc_single_threaded@GLIBC_2.32'
/usr/bin/ld: ../lib/third_party_lib.so: undefined reference to `pthread_mutex_trylock@GLIBC_2.34'
/usr/bin/ld: ../lib/third_party_lib.so: undefined reference to `pthread_getspecific@GLIBC_2.34'
/usr/bin/ld: ../lib/third_party_lib.so: undefined reference to `std::__throw_bad_array_new_length()@GLIBCXX_3.4.29'
/usr/bin/ld: ../lib/third_party_lib.so: undefined reference to `lstat@GLIBC_2.33'
/usr/bin/ld: ../lib/third_party_lib.so: undefined reference to `pthread_once@GLIBC_2.34'
/usr/bin/ld: ../lib/third_party_lib.so: undefined reference to `pthread_cond_clockwait@GLIBC_2.34'
So, I need to add pthread to my project. I tried many ways to do it but any of them works. This is the first CMakeLists:
cmake_minimum_required(VERSION 3.13)
project(reader LANGUAGES CXX)
include(GNUInstallDirs)
include (CTest)
find_package(PkgConfig REQUIRED)
add_subdirectory(dep)
add_executable("${PROJECT_NAME}")
add_subdirectory(src)
install(TARGETS ${PROJECT_NAME} RUNTIME DESTINATION ${CMAKE_INSTALL_FULL_BINDIR})
The second:
add_library("core_${PROJECT_NAME}")
target_include_directories("core_${PROJECT_NAME}" PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
add_library(third_party_lib SHARED IMPORTED)
set_property(TARGET third_party_lib PROPERTY IMPORTED_LOCATION "${CMAKE_SOURCE_DIR}/lib/third_party_lib.so")
target_include_directories("core_${PROJECT_NAME}" PUBLIC ${CMAKE_SOURCE_DIR}/dep/third_party_lib)
target_sources("core_${PROJECT_NAME}" PRIVATE
my_lib.cpp
)
target_compile_features("core_${PROJECT_NAME}" PUBLIC cxx_std_17)
target_link_libraries("core_${PROJECT_NAME}" PUBLIC
stdc++fs
)
target_sources("${PROJECT_NAME}" PRIVATE main.cpp)
target_link_libraries("${PROJECT_NAME}" PRIVATE "core_${PROJECT_NAME}" third_party_lib)
set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads REQUIRED)
target_link_libraries("${PROJECT_NAME}" PRIVATE Threads::Threads)
target_compile_features("${PROJECT_NAME}" PRIVATE cxx_std_17)
target_compile_definitions("${PROJECT_NAME}" PRIVATE
VERSION="${PROJECT_VERSION}"
)
And the third:
set(SAVED_BUILD_DOCUMENTATION ${BUILD_DOCUMENTATION})
set(BUILD_DOCUMENTATION OFF)
set(SAVED_BUILD_TESTING BUILD_TESTING)
set(BUILD_TESTING OFF)
set(BUILD_DOCUMENTATION ${SAVED_BUILD_DOCUMENTATION})
set(BUILD_TESTING ${SAVED_BUILD_TESTING})
As you can see - I'm trying to include required lib in the second CMakeLists. But the error is still here.
What else can I do?