/usr/bin/ld: cannot find -lpthreads

17,058

You have a typo. You should use -lpthread instead of -lpthreads.

Alternatively you can just use -pthread, that also works.

Share:
17,058
VansFannel
Author by

VansFannel

I'm software architect, entrepreneur and self-taught passionate with new technologies. At this moment I am studying a master's degree in advanced artificial intelligence and (in my free time ) I'm developing an immersive VR application with Unreal Engine. I have also interested in home automation applying what I'm learning with Udacity's nanodegree course in object and voice recognition.

Updated on June 04, 2022

Comments

  • VansFannel
    VansFannel almost 2 years

    I'm compiling NVIDIA Caffe tool on a Fedora 22 and I having problems to find lpthread library:

    Determining if the pthread_create exist failed with the following output:
    Change Dir: /home/user1/Sources/caffe/build/CMakeFiles/CMakeTmp
    
    Run Build Command:"/usr/bin/gmake" "cmTC_d410e/fast"
    /usr/bin/gmake -f CMakeFiles/cmTC_d410e.dir/build.make CMakeFiles/cmTC_d410e.dir/build
    gmake[1]: Entering directory '/home/user1/Sources/caffe/build/CMakeFiles/CMakeTmp'
    Building C object CMakeFiles/cmTC_d410e.dir/CheckSymbolExists.c.o
    /usr/bin/cc    -o CMakeFiles/cmTC_d410e.dir/CheckSymbolExists.c.o   -c /home/user1/Sources/caffe/build/CMakeFiles/CMakeTmp/CheckSymbolExists.c
    Linking C executable cmTC_d410e
    /usr/bin/cmake -E cmake_link_script CMakeFiles/cmTC_d410e.dir/link.txt --verbose=1
    /usr/bin/cc       CMakeFiles/cmTC_d410e.dir/CheckSymbolExists.c.o  -o cmTC_d410e -rdynamic 
    CMakeFiles/cmTC_d410e.dir/CheckSymbolExists.c.o: En la función `main':
    CheckSymbolExists.c:(.text+0x16): referencia a `pthread_create' sin definir
    collect2: error: ld devolvió el estado de salida 1
    CMakeFiles/cmTC_d410e.dir/build.make:97: recipe for target 'cmTC_d410e' failed
    gmake[1]: Leaving directory '/home/user1/Sources/caffe/build/CMakeFiles/CMakeTmp'
    Makefile:126: recipe for target 'cmTC_d410e/fast' failed
    gmake[1]: *** [cmTC_d410e] Error 1
    gmake: *** [cmTC_d410e/fast] Error 2
    
    File /home/user1/Sources/caffe/build/CMakeFiles/CMakeTmp/CheckSymbolExists.c:
    /* */
    #include <pthread.h>
    
    int main(int argc, char** argv)
    {
      (void)argv;
    #ifndef pthread_create
      return ((int*)(&pthread_create))[argc];
    #else
      (void)argc;
      return 0;
    #endif
    }
    
    Determining if the function pthread_create exists in the pthreads failed with the following output:
    Change Dir: /home/user1/Sources/caffe/build/CMakeFiles/CMakeTmp
    
    Run Build Command:"/usr/bin/gmake" "cmTC_e693b/fast"
    /usr/bin/gmake -f CMakeFiles/cmTC_e693b.dir/build.make CMakeFiles/cmTC_e693b.dir/build
    gmake[1]: Entering directory '/home/user1/Sources/caffe/build/CMakeFiles/CMakeTmp'
    Building C object CMakeFiles/cmTC_e693b.dir/CheckFunctionExists.c.o
    /usr/bin/cc   -DCHECK_FUNCTION_EXISTS=pthread_create   -o CMakeFiles/cmTC_e693b.dir/CheckFunctionExists.c.o   -c /usr/share/cmake/Modules/CheckFunctionExists.c
    Linking C executable cmTC_e693b
    /usr/bin/cmake -E cmake_link_script CMakeFiles/cmTC_e693b.dir/link.txt --verbose=1
    /usr/bin/cc   -DCHECK_FUNCTION_EXISTS=pthread_create    CMakeFiles/cmTC_e693b.dir/CheckFunctionExists.c.o  -o cmTC_e693b -rdynamic -lpthreads 
    /usr/bin/ld: cannot find -lpthreads
    collect2: error: ld outputs 1
    CMakeFiles/cmTC_e693b.dir/build.make:97: recipe for target 'cmTC_e693b' failed
    gmake[1]: Leaving directory '/home/user1/Sources/caffe/build/CMakeFiles/CMakeTmp'
    Makefile:126: recipe for target 'cmTC_e693b/fast' failed
    gmake[1]: *** [cmTC_e693b] Error 1
    gmake: *** [cmTC_e693b/fast] Error 2
    

    It seems that it doesn't find pthreads lib (/usr/bin/ld: cannot find -lpthreads), but running command find / name "*pthread*" it outputs this:

    /usr/lib64/libpthread.so
    /usr/lib64/libpthread.a
    /usr/lib64/libpthread_nonshared.a
    /usr/lib64/libpthread-2.21.so
    /usr/lib64/libpthread.so.0
    

    But there is something strange with this, becaue CMakeOutut.log has this: Determining if the function pthread_create exists in the pthread passed with the following output:

    Change Dir: /home/user1/Sources/caffe/build/CMakeFiles/CMakeTmp
    
    Run Build Command:"/usr/bin/gmake" "cmTC_705ba/fast"
    /usr/bin/gmake -f CMakeFiles/cmTC_705ba.dir/build.make CMakeFiles/cmTC_705ba.dir/build
    gmake[1]: Entering directory '/home/user1/Sources/caffe/build/CMakeFiles/CMakeTmp'
    Building C object CMakeFiles/cmTC_705ba.dir/CheckFunctionExists.c.o
    /usr/bin/cc   -DCHECK_FUNCTION_EXISTS=pthread_create   -o CMakeFiles/cmTC_705ba.dir/CheckFunctionExists.c.o   -c /usr/share/cmake/Modules/CheckFunctionExists.c
    Linking C executable cmTC_705ba
    /usr/bin/cmake -E cmake_link_script CMakeFiles/cmTC_705ba.dir/link.txt --verbose=1
    /usr/bin/cc   -DCHECK_FUNCTION_EXISTS=pthread_create    CMakeFiles/cmTC_705ba.dir/CheckFunctionExists.c.o  -o cmTC_705ba -rdynamic -lpthread 
    gmake[1]: Leaving directory '/home/user1/Sources/caffe/build/CMakeFiles/CMakeTmp'
    

    It has this line using lpthread:

    /usr/bin/cc   -DCHECK_FUNCTION_EXISTS=pthread_create    CMakeFiles/cmTC_705ba.dir/CheckFunctionExists.c.o  -o cmTC_705ba -rdynamic -lpthread
    

    And this is CMakeList.txt:

    cmake_minimum_required(VERSION 2.8.7)
    
    # ---[ Caffe project
    project(Caffe C CXX)
    
    # ---[ Caffe version
    set(CAFFE_TARGET_VERSION "0.14.5")
    set(CAFFE_TARGET_SOVERSION "0.14")
    add_definitions(-DCAFFE_VERSION=${CAFFE_TARGET_VERSION})
    
    # ---[ Using cmake scripts and modules
    list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake/Modules)
    
    include(ExternalProject)
    
    include(cmake/Utils.cmake)
    include(cmake/Targets.cmake)
    include(cmake/Misc.cmake)
    include(cmake/Summary.cmake)
    include(cmake/ConfigGen.cmake)
    
    # ---[ Options
    caffe_option(CPU_ONLY  "Build Caffe without CUDA support" OFF) # TODO: rename to USE_CUDA
    caffe_option(USE_CUDNN "Build Caffe with cuDNN library support" ON IF NOT CPU_ONLY)
    caffe_option(BUILD_SHARED_LIBS "Build shared libraries" ON)
    caffe_option(BUILD_python "Build Python wrapper" ON)
    set(python_version "2" CACHE STRING "Specify which Python version to use")
    caffe_option(BUILD_matlab "Build Matlab wrapper" OFF IF UNIX OR APPLE)
    caffe_option(BUILD_docs   "Build documentation" ON IF UNIX OR APPLE)
    caffe_option(BUILD_python_layer "Build the Caffe Python layer" ON)
    caffe_option(USE_OPENCV "Build with OpenCV support" ON)
    caffe_option(USE_LEVELDB "Build with levelDB" ON)
    caffe_option(USE_LMDB "Build with lmdb" ON)
    caffe_option(ALLOW_LMDB_NOLOCK "Allow MDB_NOLOCK when reading LMDB files (only if necessary)" OFF)
    
    # ---[ Dependencies
    include(cmake/Dependencies.cmake)
    
    # ---[ Flags
    if(UNIX OR APPLE)
      set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC -Wall")
    endif()
    
    if(USE_libstdcpp)
      set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libstdc++")
      message("-- Warning: forcing libstdc++ (controlled by USE_libstdcpp option in cmake)")
    endif()
    
    add_definitions(-DGTEST_USE_OWN_TR1_TUPLE)
    
    # ---[ Warnings
    caffe_warnings_disable(CMAKE_CXX_FLAGS -Wno-sign-compare -Wno-uninitialized)
    
    # ---[ Config generation
    configure_file(cmake/Templates/caffe_config.h.in "${PROJECT_BINARY_DIR}/caffe_config.h")
    
    # ---[ Includes
    set(Caffe_INCLUDE_DIR ${PROJECT_SOURCE_DIR}/include)
    set(THIRDPARTY_DIR ${PROJECT_SOURCE_DIR}/3rdparty)
    include_directories(${Caffe_INCLUDE_DIR} ${PROJECT_BINARY_DIR} ${THIRDPARTY_DIR})
    include_directories(BEFORE src) # This is needed for gtest.
    
    # ---[ Subdirectories
    add_subdirectory(src/gtest)
    add_subdirectory(src/caffe)
    add_subdirectory(tools)
    add_subdirectory(examples)
    add_subdirectory(python)
    add_subdirectory(matlab)
    add_subdirectory(docs)
    
    # ---[ Linter target
    add_custom_target(lint COMMAND ${CMAKE_COMMAND} -P ${PROJECT_SOURCE_DIR}/cmake/lint.cmake)
    
    # ---[ pytest target
    add_custom_target(pytest COMMAND python${python_version} -m unittest discover -s caffe/test WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/python )
    add_dependencies(pytest pycaffe)
    
    # ---[ Configuration summary
    caffe_print_configuration_summary()
    
    # ---[ Export configs generation
    caffe_generate_export_configs()
    

    What do I have to install? Does libphreads exist or I have to use libphread?

  • VansFannel
    VansFannel almost 8 years
    Maybe Caffe has a typo. I'm only running cmake ..
  • Smeeheey
    Smeeheey almost 8 years
    Then you should share your cmake config file. Somewhere therein there will be an incorrect definition of the pthread switch value
  • Smeeheey
    Smeeheey almost 8 years
    It'll most likely be called CMakeLists or CMakeLists.txt
  • VansFannel
    VansFannel almost 8 years
    I have updated my question with the contents of CMakeLists.txt.
  • Matt Schuchard
    Matt Schuchard almost 8 years
    I just did a search on pthreads in the nvidia/caffe project and nothing was found in the current commit. Sounds like a reclone would fix the typo.