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

I'm on fedora 18 64-bit.

find_package(Threads REQUIRED)
target_link_libraries(app_suite_tests ${CMAKE_THREAD_LIBS_INIT})

is the code that is creating this. What can I do to prevent CMake from throwing an error here, or how can I get CMake to check the pthreads library over the executable?

Thanks.

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()

Is from FindThreads.cmake, and the error is thrown on CHECK_LIBRARY_EXISTS

clark
  • 395
  • 5
  • 12

2 Answers2

1

This error is specific to cmake 2.8.11+ and a project that has an executable target named "pthreads". That is the executable that cmake trips over. Renaming the executable resolves the issue. See also the Dr. Memory issue tracker entry on this.

Derek Bruening
  • 330
  • 2
  • 5
0

I think you are looking for

ADD_EXECUTABLE(your_executable ${source_files})

TARGET_LINK_LIBRARIES(
pthread
)

taken from cmake and libpthread

Community
  • 1
  • 1
Najzero
  • 3,164
  • 18
  • 18
  • Not quite I think. CMake is checking for pthread_create in pthreads, and then complaining that pthreads is an executable and not a library. I commented out the pthreads check in FindThreads.cmake, but I then fail a bunch of tests. I think I might be missing something. – clark Jun 05 '13 at 17:41