Skip to content
This repository has been archived by the owner on Feb 7, 2023. It is now read-only.

CMakeError: /usr/bin/ld: cannot find -lpthreads #1234

Closed
jacob1017 opened this issue Sep 19, 2017 · 22 comments
Closed

CMakeError: /usr/bin/ld: cannot find -lpthreads #1234

jacob1017 opened this issue Sep 19, 2017 · 22 comments
Labels

Comments

@jacob1017
Copy link

/usr/lib64/ccache/cc CMakeFiles/cmTryCompileExec580799551.dir/CheckSymbolExists.c.o -o cmTryCompileExec580799551 -rdynamic
CMakeFiles/cmTryCompileExec580799551.dir/CheckSymbolExists.c.o: In function main': CheckSymbolExists.c:(.text+0x16): undefined reference to pthread_create'
collect2: error: ld returned 1 exit status
gmake[2]: *** [cmTryCompileExec580799551] Error 1
gmake[2]: Leaving directory /home/jiangbo/caffe2/build/CMakeFiles/CMakeTmp' gmake[1]: *** [cmTryCompileExec580799551/fast] Error 2 gmake[1]: Leaving directory /home/jiangbo/caffe2/build/CMakeFiles/CMakeTmp'

File /home/jiangbo/caffe2/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/jiangbo/caffe2/build/CMakeFiles/CMakeTmp

Run Build Command:/usr/bin/gmake "cmTryCompileExec3472543844/fast"
gmake[1]: Entering directory /home/jiangbo/caffe2/build/CMakeFiles/CMakeTmp' /usr/bin/gmake -f CMakeFiles/cmTryCompileExec3472543844.dir/build.make CMakeFiles/cmTryCompileExec3472543844.dir/build gmake[2]: Entering directory /home/jiangbo/caffe2/build/CMakeFiles/CMakeTmp'
/usr/bin/cmake -E cmake_progress_report /home/jiangbo/caffe2/build/CMakeFiles/CMakeTmp/CMakeFiles 1
Building C object CMakeFiles/cmTryCompileExec3472543844.dir/CheckFunctionExists.c.o
/usr/lib64/ccache/cc -DCHECK_FUNCTION_EXISTS=pthread_create -o CMakeFiles/cmTryCompileExec3472543844.dir/CheckFunctionExists.c.o -c /usr/share/cmake/Modules/CheckFunctionExists.c
Linking C executable cmTryCompileExec3472543844
/usr/bin/cmake -E cmake_link_script CMakeFiles/cmTryCompileExec3472543844.dir/link.txt --verbose=1
/usr/lib64/ccache/cc -DCHECK_FUNCTION_EXISTS=pthread_create CMakeFiles/cmTryCompileExec3472543844.dir/CheckFunctionExists.c.o -o cmTryCompileExec3472543844 -rdynamic -lpthreads
/usr/bin/ld: cannot find -lpthreads
collect2: error: ld returned 1 exit status
gmake[2]: *** [cmTryCompileExec3472543844] Error 1
gmake[2]: Leaving directory /home/jiangbo/caffe2/build/CMakeFiles/CMakeTmp' gmake[1]: *** [cmTryCompileExec3472543844/fast] Error 2 gmake[1]: Leaving directory /home/jiangbo/caffe2/build/CMakeFiles/CMakeTmp'

Performing C++ SOURCE FILE Test CAFFE2_NEED_TO_TURN_OFF_DEPRECATION_WARNING failed with the following output:
Change Dir: /home/jiangbo/caffe2/build/CMakeFiles/CMakeTmp

Run Build Command:/usr/bin/gmake "cmTryCompileExec1218977336/fast"
gmake[1]: Entering directory /home/jiangbo/caffe2/build/CMakeFiles/CMakeTmp' /usr/bin/gmake -f CMakeFiles/cmTryCompileExec1218977336.dir/build.make CMakeFiles/cmTryCompileExec1218977336.dir/build gmake[2]: Entering directory /home/jiangbo/caffe2/build/CMakeFiles/CMakeTmp'
/usr/bin/cmake -E cmake_progress_report /home/jiangbo/caffe2/build/CMakeFiles/CMakeTmp/CMakeFiles 1
Building CXX object CMakeFiles/cmTryCompileExec1218977336.dir/src.cxx.o
/usr/lib64/ccache/c++ -fopenmp -DCAFFE2_NEED_TO_TURN_OFF_DEPRECATION_WARNING -std=c++11 -o CMakeFiles/cmTryCompileExec1218977336.dir/src.cxx.o -c /home/jiangbo/caffe2/build/CMakeFiles/CMakeTmp/src.cxx
In file included from /usr/include/c++/4.8.2/ext/hash_set:60:0
.....

I use ldconfig -h | grep pthread can find the library, libpthreads. Google this problem, may be some error in the code if i use cmake 3.8 version. ## please tell me where to change -lptheads to -lpthread.

@pietern
Copy link
Contributor

pietern commented Sep 21, 2017

Can you please share the chunk of CMake output that prints whether or not pthreads is found. Also the output of ldconfig -p | grep pthread. Instead of changing some variable I would rather understand why this is happening so we can prevent this from happening again. Thanks.

@pietern pietern added the build label Sep 21, 2017
@jacob1017
Copy link
Author

I have tried gcc 5.3/ 4.8.2 cmake 3.8 and -lpthread for my own pthread test case. But this error occurs and I don't know why, any ideas for this,please contact me .

@jacob1017
Copy link
Author

@pietern
ldconfig -p | grep pthread
libpthread.so.0 (libc6,x86-64, OS ABI: Linux 2.6.32) => /lib64/libpthread.so.0
liblttng-ust-pthread-wrapper.so.0 (libc6,x86-64) => /lib64/liblttng-ust-pthread-wrapper.so.0
liblttng-ust-pthread-wrapper.so (libc6,x86-64) => /lib64/liblttng-ust-pthread-wrapper.so
libgpgme-pthread.so.11 (libc6,x86-64) => /lib64/libgpgme-pthread.so.11
libevent_pthreads-2.0.so.5 (libc6,x86-64) => /lib64/libevent_pthreads-2.0.so.5

caffe is ok, but caffe2 failed.

@gauravchauhangc
Copy link

ubuntu@ubuntu:~/Downloads/alter/src$ make -f makefile.unix
/bin/sh ../share/genbuild.sh obj/build.h
g++ -O2 -pthread -Wall -Wextra -Wformat -Wformat-security -Wno-unused-parameter -g -DBOOST_SPIRIT_THREADSAFE -D_FILE_OFFSET_BITS=64 -I/home/ubuntu/Downloads/litecoin/src -I/home/ubuntu/Downloads/litecoin/src/obj -DUSE_UPNP=0 -DUSE_IPV6=1 -I/home/ubuntu/Downloads/litecoin/src/leveldb/include -I/home/ubuntu/Downloads/litecoin/src/leveldb/helpers -DHAVE_BUILD_INFO -fno-stack-protector -fstack-protector-all -Wstack-protector -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 -o ordeald leveldb/libleveldb.a obj/alert.o obj/version.o obj/checkpoints.o obj/netbase.o obj/addrman.o obj/crypter.o obj/key.o obj/db.o obj/init.o obj/keystore.o obj/main.o obj/net.o obj/protocol.o obj/bitcoinrpc.o obj/rpcdump.o obj/rpcnet.o obj/rpcmining.o obj/rpcwallet.o obj/rpcblockchain.o obj/rpcrawtransaction.o obj/script.o obj/scrypt.o obj/sync.o obj/util.o obj/wallet.o obj/walletdb.o obj/hash.o obj/bloom.o obj/noui.o obj/leveldb.o obj/txdb.o -Wl,-z,relro -Wl,-z,now -Wl,-Bdynamic -l boost_system -l boost_filesystem -l boost_program_options -l boost_thread -l db_cxx -l ssl -l crypto -l miniupnpc -Wl,-Bdynamic -l z -l dl -l pthread /home/ubuntu/Downloads/alter/src/leveldb/libleveldb.a /home/ubuntu/Downloads/alter/src/leveldb/libmemenv.a
/usr/bin/ld: cannot find -lboost_system
/usr/bin/ld: cannot find -lboost_filesystem
/usr/bin/ld: cannot find -lboost_program_options
/usr/bin/ld: cannot find -lboost_thread
collect2: error: ld returned 1 exit status
makefile.unix:193: recipe for target 'alterd' failed
make: *** [alter] Error 1

how to solve this typr of error? please give me solution.....Thanks

@eyalroz
Copy link

eyalroz commented Oct 8, 2017

Facing a similar issue with another repository - this may-or-may-not be a problem specific to caffe2.

@DRyan1995
Copy link

I fixed this issue by using the --recursive when I git clone the caffe2 repos from the github.
Sounds wired but it did work.

Thanks,

@galian123
Copy link

I met the similar issue and found that caffe2 code was not downloaded completely.
I use "git clone --recursive https://github.com/caffe2/caffe2.git" to download caffe2.
Then use "git submodule update --init --recursive" to make sure all submodules are downloaded completely.
Then run 'make' successfully.

@jacob1017
Copy link
Author

Thanks @galian123 @DRyan1995 , I have fixed this issue just add --recursive when we clone caffe2. Another tips should also be noticed that glog and gflags compile error. I have configure glog OFF to around this error.

Thanks .

@jacob1017
Copy link
Author

This issue has been solved, so I would close it .

@wincle
Copy link

wincle commented Feb 11, 2018

Met the same error , I have tried git submodule update --init --recursive , but didn't fixed it, how did you solved the problem ? Thx!

@JamesKBowler
Copy link

I am also getting this error.

@liuyuisanai
Copy link

hi @wincle and @JamesKBowler
I encountered the same problem and --recursive doesn't work.
Finally I solved this issue by upgrading cmake from 3.2 to 3.10
Seems there's a bug in cmake 3.2 in my case.
Hope it would help.

@akakcolin
Copy link

I am also getting this error.

@manketon
Copy link

@DRyan1995 @galian123 I encountered timeout when cloning caffe2. Would you send the caffe2 source code package to me ? The address of my email is 850268547@qq.com, thank you.

@jin-zhe
Copy link

jin-zhe commented Jun 22, 2018

I encountered this error because git submodule update --init --recursive couldn't get past the third_party/eigen repository and so the other third_party submodules weren't getting cloned in. This was due to https://github.com/RLovelett/eigen.git being recently made unavailable by @RLovelett. Since this submodule isn't necessary if you have system eigen, I simply removed the submodule from the local caffe2 repository and cmake ran successfully afterwards.

I removed the submodule via the following steps:

  1. Remove the following lines from .gitmodules:
[submodule "third_party/eigen"]
	path = third_party/eigen
	url = https://github.com/RLovelett/eigen.git
  1. git add .gitmodules
  2. git rm --cached third_party/eigen
  3. rm -rf .git/modules/third_party/eigen
  4. rm -rf third_party/eigen

@orionr
Copy link
Contributor

orionr commented Jun 22, 2018

Hi @jin-zhe - best would be to clone from https://github.com/pytorch/pytorch now. All the code should exist over there and we've updated the eigen submodule. Hope that helps.

@xiachsh
Copy link

xiachsh commented Jun 25, 2018

There are two problems here i found

  1. the pthread problem
    it's maybe a bug of cmake, i fix this with following patch of FindThreads.cmake under /usr/share/cmake-x.x/Modules
    `
    root@NV-ubuntu-01:/usr/share/cmake-3.5/Modules# diff -uNpr FindThreads.cmake FindThreads.cmake.bak
    --- FindThreads.cmake 2018-06-25 18:03:58.570963757 +0800
    +++ FindThreads.cmake.bak 2018-06-25 17:42:09.320845095 +0800
    @@ -149,12 +149,12 @@ else()
    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)
    
  •  #else()
    
  •  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)
    
  •  else()
    
       # Check for -pthread first if enabled. This is the recommended
       # way, but not backwards compatible as one must also pass -pthread
    

@@ -163,13 +163,13 @@ else()
_check_pthreads_flag()
endif ()

  •  #  _check_threads_lib(pthreads pthread_create CMAKE_HAVE_PTHREADS_CREATE)
    
  •    _check_threads_lib(pthreads pthread_create CMAKE_HAVE_PTHREADS_CREATE)
       _check_threads_lib(pthread  pthread_create CMAKE_HAVE_PTHREAD_CREATE)
       if(CMAKE_SYSTEM_NAME MATCHES "SunOS")
           # On sun also check for -lthread
           _check_threads_lib(thread thr_create CMAKE_HAVE_THR_CREATE)
       endif()
    
  •  #endif()
    
  •  endif()
    

    endif()

    _check_pthreads_flag()
    @@ -233,8 +233,3 @@ if(THREADS_FOUND AND NOT TARGET Threads:
    set_property(TARGET Threads::Threads PROPERTY INTERFACE_LINK_LIBRARIES "${CMAKE_THREAD_LIBS_INIT}")
    endif()
    endif()

-if (Threads_FOUND )

  •   message(STATUS "xiachsh debug Thread found ")
    

-endif()
root@NV-ubuntu-01:/usr/share/cmake-3.5/Modules#
`

  1. the third-party problem
    you should clone the caffe2 repo with option --recursive

@JaosonMa
Copy link

JaosonMa commented Jul 6, 2018

@xiachsh what did you change? i am not so understand? can you give me your FindThreads.cmake that you are using now?

@adnakateg
Copy link

Isn't it the last 's' that's causing the issue
-lpthread
OR
-lpthreads
???

@rafikg
Copy link

rafikg commented Nov 20, 2018

@orionr Hi,
I am installing Caffe2 using this tutorial Install Caffe2 with anaconda. I am using Ubuntu 18.0.4 and Anaconda3. I meet also the error undefined reference to pthread_create'

@orionr
Copy link
Contributor

orionr commented Nov 20, 2018

@Gouiaa did you do git clone --recursive ... when cloning the repository? Other than that, I'm wondering if you need to install pthread on the machine.

@rafikg
Copy link

rafikg commented Nov 27, 2018

@orionr I am running a project on caffe2 and I have these warnings:
I insalled the binary version with cuda-9.2 on ubuntu 18.04

I1127 12:34:32.921870  5339 operator.cc:195] Engine CUDNN is not available for operator MaxPool.
I1127 12:34:32.927042  5339 operator.cc:195] Engine CUDNN is not available for operator MaxPool.
I1127 12:34:32.928066  5339 net_dag_utils.cc:102] Operator graph pruning prior to chain compute took: 6.6141e-05 secs
I1127 12:34:32.930972  5339 operator.cc:195] Engine CUDNN is not available for operator MaxPool.
I1127 12:34:32.936424  5339 operator.cc:195] Engine CUDNN is not available for operator MaxPool.
How to fix that ?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests