-- Looking for include file pthread.h
-- Looking for include file pthread.h - found
-- Looking for pthread_create
-- Looking for pthread_create - not found
-- Looking for pthread_create in pthreads CMake Error at /usr/share/cmake/Modules/CheckLibraryExists.cmake:41 (try_compile): Only libraries may be used as try_compile IMPORTED LINK_LIBRARIES. Got pthreads of type EXECUTABLE. Call Stack (most recent call first): /usr/share/cmake/Modules/FindThreads.cmake:58 (CHECK_LIBRARY_EXISTS) tests/app_suite/CMakeLists.txt:58 (find_package)
-- Looking for pthread_create in pthreads - not found
-- Looking for pthread_create in pthread
-- Looking for pthread_create in pthread - found
-- Found Threads: TRUE
我在fedora 18 64位上。
find_package(Threads REQUIRED)
target_link_libraries(app_suite_tests ${CMAKE_THREAD_LIBS_INIT})
是创建此代码的代码。我该怎么做才能防止CMake在这里抛出错误,或者我如何让CMake通过可执行文件检查pthreads库?
感谢。
Additonal Info:
if(NOT CMAKE_HAVE_THREADS_LIBRARY)
# Do we have -lpthreads
CHECK_LIBRARY_EXISTS(pthreads pthread_create "" CMAKE_HAVE_PTHREADS_CREATE)
if(CMAKE_HAVE_PTHREADS_CREATE)
set(CMAKE_THREAD_LIBS_INIT "-lpthreads")
set(CMAKE_HAVE_THREADS_LIBRARY 1)
set(Threads_FOUND TRUE)
endif()
来自FindThreads.cmake,并在CHECK_LIBRARY_EXISTS
上抛出错误答案 0 :(得分:1)
此错误特定于cmake 2.8.11+以及具有名为“pthreads”的可执行目标的项目。这是cmake绊倒的可执行文件。重命名可执行文件可解决此问题。另请参阅the Dr. Memory issue tracker entry on this。
答案 1 :(得分:0)
我认为你在寻找
ADD_EXECUTABLE(your_executable ${source_files})
TARGET_LINK_LIBRARIES(
pthread
)