0
-- 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 库?

谢谢。

附加信息:

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 上抛出

4

2 回答 2

1

此错误特定于 cmake 2.8.11+ 和具有名为“pthreads”的可执行目标的项目。那是 cmake 绊倒的可执行文件。重命名可执行文件可解决此问题。另请参阅有关此的 Dr. Memory 问题跟踪器条目

于 2013-06-06T15:47:40.820 回答
0

我想你正在寻找

ADD_EXECUTABLE(your_executable ${source_files})

TARGET_LINK_LIBRARIES(
pthread
)

取自cmake 和 libpthread

于 2013-06-04T07:28:23.807 回答