La construction d'erreur en utilisant cmake: ne peut trouver -lpthreads

J'ai le c++ projet qui a été en douceur, en cours d'exécution sur une machine donnée, et maintenant j'essaie de le compiler sur un autre avec le même système d'exploitation (Xubuntu 14.04).

J'ai installé toutes les dépendances et je suis en utilisant cmake pour construire le projet, bien qu'il s'arrête avec le message d'erreur suivant:

Déterminer si la fonction pthread_create existe dans les pthreads a échoué avec la sortie suivante:
...
/usr/bin/ld: ne peut trouver -lpthreads

L'cmakelists.txt les lignes qui incluent les drapeaux du compilateur sont comme suit:

set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O3 -lpthread -DNDEBUG -DEIGEN_MPL2_ONLY")
set(CMAKE_C_FLAGS_DEBUG "-g -O0 -Wall -lpthread -DEIGEN_MPL2_ONLY")
set(CMAKE_CXX_FLAGS "${CMAKE_C_FLAGS} -O3 -lpthread -I/usr/include/freetype2 -DNDEBUG -DEIGEN_MPL2_ONLY")
set(CMAKE_CXX_FLAGS_DEBUG "-g -O0 -Wall -lpthread -I/usr/include/freetype2 -DEIGEN_MPL2_ONLY")

J'ai fait quelques recherches et ont déjà essayé ce qui suit:

-utilisé -pthread/threads/threads/-lpthreads au lieu de -lpthread, ce qui ne permet pas de résoudre le problème et rend la construction d'arrêt, sans trouver le package suivant:
find_package (Threads)

  • changé l'ordre de-lpthread dans le cmakelists ligne ci-dessus, qui donne la même erreur
  • utilisé différentes versions o gcc/g++: essayé 4.4, 4.6 et 4.8, sans aucun changement
  • créé un lien symbolique vers libpthread.donc dans /usr/lib/, sans aucun changement

J'apprécierais un peu d'aide, car je suis déjà en manque d'idées sur ce à essayer ensuite.

Edit 1

La bibliothèque est l'endroit où il se doit:

$ find /lib -name "*pthread*"
/lib/x86_64-linux-gnu/libpthread-2.19.so
/lib/x86_64-linux-gnu/libpthread.so.0

La pthread_create est également trouvée:

$ nm /lib/x86_64-linux-gnu/libpthread.so.0 | grep "pthread_create"
0000000000008430 t __pthread_create_2_1
00000000000081430 T pthread_create@@GLIBC_2.2.5

J'ai également vérifié que les deux libpthread-stubs0 et libc6-dev sont présents.

Edit 2

C'est une partie de la FindThreads.cmake contenu d'un fichier qui se trouve dans /usr/share/cmake-2.8/Modules/:

if(CMAKE_HAVE_SPROC_H AND NOT CMAKE_THREAD_PREFER_PTHREAD)
# We have sproc
set(CMAKE_USE_SPROC_INIT 1)
else()
# Do we have pthreads?
CHECK_INCLUDE_FILES("pthread.h" CMAKE_HAVE_PTHREAD_H)
if(CMAKE_HAVE_PTHREAD_H)
#
# We have pthread.h
# Let's check for the library now.
#
set(CMAKE_HAVE_THREADS_LIBRARY)
if(NOT THREADS_HAVE_PTHREAD_ARG)
# Check if pthread functions are in normal C library
CHECK_SYMBOL_EXISTS(pthread_create pthread.h CMAKE_HAVE_LIBC_CREATE)
if(CMAKE_HAVE_LIBC_CREATE)
set(CMAKE_THREAD_LIBS_INIT "")
set(CMAKE_HAVE_THREADS_LIBRARY 1)
set(Threads_FOUND TRUE)
endif()
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()
# Ok, how about -lpthread
CHECK_LIBRARY_EXISTS(pthread pthread_create "" CMAKE_HAVE_PTHREAD_CREATE)
if(CMAKE_HAVE_PTHREAD_CREATE)
set(CMAKE_THREAD_LIBS_INIT "-lpthread")
set(CMAKE_HAVE_THREADS_LIBRARY 1)
set(Threads_FOUND TRUE)
endif()
if(CMAKE_SYSTEM MATCHES "SunOS.*")
# On sun also check for -lthread
CHECK_LIBRARY_EXISTS(thread thr_create "" CMAKE_HAVE_THR_CREATE)
if(CMAKE_HAVE_THR_CREATE)
set(CMAKE_THREAD_LIBS_INIT "-lthread")
set(CMAKE_HAVE_THREADS_LIBRARY 1)
set(Threads_FOUND TRUE)
endif()
endif()
endif()
endif()
if(NOT CMAKE_HAVE_THREADS_LIBRARY)
# If we did not found -lpthread, -lpthread, or -lthread, look for -pthread
if("THREADS_HAVE_PTHREAD_ARG" MATCHES "^THREADS_HAVE_PTHREAD_ARG")
message(STATUS "Check if compiler accepts -pthread")
try_run(THREADS_PTHREAD_ARG THREADS_HAVE_PTHREAD_ARG
${CMAKE_BINARY_DIR}
${CMAKE_ROOT}/Modules/CheckForPthreads.c
CMAKE_FLAGS -DLINK_LIBRARIES:STRING=-pthread
COMPILE_OUTPUT_VARIABLE OUTPUT)
if(THREADS_HAVE_PTHREAD_ARG)
if(THREADS_PTHREAD_ARG STREQUAL "2")
set(Threads_FOUND TRUE)
message(STATUS "Check if compiler accepts -pthread - yes")
else()
message(STATUS "Check if compiler accepts -pthread - no")
file(APPEND
${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log
"Determining if compiler accepts -pthread returned ${THREADS_PTHREAD_ARG} instead of 2. The compiler had the following output:\n${OUTPUT}\n\n")
endif()
else()
message(STATUS "Check if compiler accepts -pthread - no")
file(APPEND
${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log
"Determining if compiler accepts -pthread failed with the following output:\n${OUTPUT}\n\n")
endif()
endif()
if(THREADS_HAVE_PTHREAD_ARG)
set(Threads_FOUND TRUE)
set(CMAKE_THREAD_LIBS_INIT "-pthread")
endif()
endif()
endif()
endif()

Modifier 3

Utilisé un minimum Cmakelists.txt comme suit:

cmake_minimum_required (VERSION 2.4)
find_package(Threads)

Qui produit la sortie suivante:

-- 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
-- Looking for pthread_create in pthreads - not found
-- Looking for pthread_create in pthread
-- Looking for pthread_create in pthread - found
-- Found Threads: TRUE 
Probablement sans rapport mais ne pas utiliser de -lpthread. Utilisation -pthread, à la fois pour la compilation et la liaison.
Aide -pthread ne résout pas le problème non plus.
Alors, avez-vous réussi à surmonter ce problème en quelque sorte? Je suis face à elle en ce moment...
Il l'a fait, voir les commentaires ci-dessous la réponse. Malheureusement, Sapiens obligeance de ne pas mentionner le paquet était la version-incompatibles.

OriginalL'auteur Sapiens | 2015-08-11