Ask Your Question
0

x86_64-unknown-linux-gnu/bin/ld: cannot find -lpthreads

asked 2018-05-04 09:41:59 -0500

updated 2018-05-04 13:40:02 -0500

I'm installing opencv 3.3 with centOS 6.9, gcc 4.8.5, cmake 3.11.1 ,cuda 9.0 and cudnn 7.0. I have been stuck on this question for quite a while. cmake error output as below.

CMakeFiles/cmTC_09750.dir/CheckSymbolExists.c.o: In function `main':
**CheckSymbolExists.c:(.text.startup+0x3): undefined reference to `pthread_create'**
collect2: error: ld returned 1 exit status
gmake[1]: *** [cmTC_09750] Error 1
gmake[1]: Leaving directory `/home/cch/Downloads/opencv/build/CMakeFiles/CMakeTmp'
gmake: *** [cmTC_09750/fast] Error 2

File /home/cch/Downloads/opencv/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/cch/Downloads/opencv/build/CMakeFiles/CMakeTmp

Run Build Command:"/usr/bin/gmake" "cmTC_c092d/fast"
/usr/bin/gmake -f CMakeFiles/cmTC_c092d.dir/build.make CMakeFiles/cmTC_c092d.dir/build
gmake[1]: Entering directory `/home/cch/Downloads/opencv/build/CMakeFiles/CMakeTmp'
Building C object CMakeFiles/cmTC_c092d.dir/CheckFunctionExists.c.o
/usr/bin/cc   -fPIC -DCHECK_FUNCTION_EXISTS=pthread_create -O3 -DNDEBUG   -o CMakeFiles/cmTC_c092d.dir/CheckFunctionExists.c.o   -c /usr/local/cmake-3.11.1/share/cmake-3.11/Modules/CheckFunctionExists.c
Linking C executable cmTC_c092d
/usr/local/cmake-3.11.1/bin/cmake -E cmake_link_script CMakeFiles/cmTC_c092d.dir/link.txt --verbose=1
/usr/bin/cc -fPIC -DCHECK_FUNCTION_EXISTS=pthread_create -O3 -DNDEBUG     -rdynamic CMakeFiles/cmTC_c092d.dir/CheckFunctionExists.c.o  -o cmTC_c092d -lpthreads
**/usr/lib/gcc/x86_64-unknown-linux-gnu/4.8.5/../../../../x86_64-unknown-linux-gnu/bin/ld: cannot find -lpthreads**
collect2: error: ld returned 1 exit status
gmake[1]: *** [cmTC_c092d] Error 1
gmake[1]: Leaving directory `/home/cch/Downloads/opencv/build/CMakeFiles/CMakeTmp'
gmake: *** [cmTC_c092d/fast] Error 2

> [root@IB1 include]# ldconfig -v | grep
> pthread ldconfig:
> /etc/ld.so.conf.d/kernel-2.6.32-696.el6.x86_64.conf:6:
> duplicate hwcap 1 nosegneg ldconfig:
> Path `/lib64' given more than once
> ldconfig: Can't stat /libx32: No such
> file or directory ldconfig: Can't stat
> /usr/libx32: No such file or directory
>   libpthread.so.0 -> libpthread-2.17.so
>   libpthread.so.0 -> libpthread-2.12.so
> ldconfig: Cannot stat
> /usr/lib64/libGL.so: No such file or
> directory     libgpgme-pthread.so.11 ->
> libgpgme-pthread.so.11.6.6
>   libpthread.so.0 -> libpthread-2.12.so

I wonder what I should do next?

edit retag flag offensive close merge delete

Comments

Seems like someone somewhere is using the library name pthreads instead of pthread. The correct library to link with is -lpthread, not -lpthreads.

opalmirror gravatar imageopalmirror ( 2018-05-04 13:38:15 -0500 )edit

Nobody is. Cmake tries -lpthreads internally, then -lpthread, then goes off and does something else, which fails silently.

MatthiasU gravatar imageMatthiasU ( 2019-02-05 04:06:50 -0500 )edit

1 answer

Sort by ยป oldest newest most voted
0

answered 2019-02-05 04:15:59 -0500

That appears to be a long-standing CMake bug. Something else is going wrong and CMake gets confused. Look for "thread" in your CMakeLists.txt file and temporarily remove that.

edit flag offensive delete link more
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2018-05-04 09:41:59 -0500

Seen: 471 times

Last updated: May 04 '18