Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

/usr/bin/ld: 找不到 -lpthreads #130

Closed
cdoco opened this issue Apr 14, 2021 · 4 comments
Closed

/usr/bin/ld: 找不到 -lpthreads #130

cdoco opened this issue Apr 14, 2021 · 4 comments

Comments

@cdoco
Copy link
Contributor

cdoco commented Apr 14, 2021

ubuntu 20.04

Performing C SOURCE FILE Test CMAKE_HAVE_LIBC_PTHREAD failed with the following output:
Change Dir: /data/deps/QConf-1.2.1/build/CMakeFiles/CMakeTmp

Run Build Command(s):/usr/bin/make cmTC_8fe75/fast && /usr/bin/make -f CMakeFiles/cmTC_8fe75.dir/build.make CMakeFiles/cmTC_8fe75.dir/build
make[1]: 进入目录“/data/deps/QConf-1.2.1/build/CMakeFiles/CMakeTmp”
Building C object CMakeFiles/cmTC_8fe75.dir/src.c.o
/usr/bin/cc   -DCMAKE_HAVE_LIBC_PTHREAD   -o CMakeFiles/cmTC_8fe75.dir/src.c.o   -c /data/deps/QConf-1.2.1/build/CMakeFiles/CMakeTmp/src.c
Linking C executable cmTC_8fe75
/usr/bin/cmake -E cmake_link_script CMakeFiles/cmTC_8fe75.dir/link.txt --verbose=1
/usr/bin/cc  -DCMAKE_HAVE_LIBC_PTHREAD    -rdynamic CMakeFiles/cmTC_8fe75.dir/src.c.o  -o cmTC_8fe75 
/usr/bin/ld: CMakeFiles/cmTC_8fe75.dir/src.c.o: in function `main':
src.c:(.text+0x46): undefined reference to `pthread_create'
/usr/bin/ld: src.c:(.text+0x52): undefined reference to `pthread_detach'
/usr/bin/ld: src.c:(.text+0x63): undefined reference to `pthread_join'
collect2: error: ld returned 1 exit status
make[1]: *** [CMakeFiles/cmTC_8fe75.dir/build.make:87:cmTC_8fe75] 错误 1
make[1]: 离开目录“/data/deps/QConf-1.2.1/build/CMakeFiles/CMakeTmp”
make: *** [Makefile:121:cmTC_8fe75/fast] 错误 2


Source file was:
#include <pthread.h>

void* test_func(void* data)
{
  return data;
}

int main(void)
{
  pthread_t thread;
  pthread_create(&thread, NULL, test_func, NULL);
  pthread_detach(thread);
  pthread_join(thread, NULL);
  pthread_atfork(NULL, NULL, NULL);
  pthread_exit(NULL);

  return 0;
}

Determining if the function pthread_create exists in the pthreads failed with the following output:
Change Dir: /data/deps/QConf-1.2.1/build/CMakeFiles/CMakeTmp

Run Build Command(s):/usr/bin/make cmTC_6e680/fast && /usr/bin/make -f CMakeFiles/cmTC_6e680.dir/build.make CMakeFiles/cmTC_6e680.dir/build
make[1]: 进入目录“/data/deps/QConf-1.2.1/build/CMakeFiles/CMakeTmp”
Building C object CMakeFiles/cmTC_6e680.dir/CheckFunctionExists.c.o
/usr/bin/cc   -DCHECK_FUNCTION_EXISTS=pthread_create   -o CMakeFiles/cmTC_6e680.dir/CheckFunctionExists.c.o   -c /usr/share/cmake-3.16/Modules/CheckFunctionExists.c
Linking C executable cmTC_6e680
/usr/bin/cmake -E cmake_link_script CMakeFiles/cmTC_6e680.dir/link.txt --verbose=1
/usr/bin/cc  -DCHECK_FUNCTION_EXISTS=pthread_create    -rdynamic CMakeFiles/cmTC_6e680.dir/CheckFunctionExists.c.o  -o cmTC_6e680  -lpthreads 
/usr/bin/ld: 找不到 -lpthreads
collect2: error: ld returned 1 exit status
make[1]: *** [CMakeFiles/cmTC_6e680.dir/build.make:87:cmTC_6e680] 错误 1
make[1]: 离开目录“/data/deps/QConf-1.2.1/build/CMakeFiles/CMakeTmp”
make: *** [Makefile:121:cmTC_6e680/fast] 错误 2

查看 /usr/lib/x86_64-linux-gnu 是存在 libpthread.so

deps/QConf-1.2.1/build » l /usr/lib/x86_64-linux-gnu/libpthread*                    
-rwxr-xr-x 1 root root 154K 12月 16 19:04 /usr/lib/x86_64-linux-gnu/libpthread-2.31.so
-rw-r--r-- 1 root root 6.3M 12月 16 19:04 /usr/lib/x86_64-linux-gnu/libpthread.a
lrwxrwxrwx 1 root root   37 12月 16 19:04 /usr/lib/x86_64-linux-gnu/libpthread.so -> /lib/x86_64-linux-gnu/libpthread.so.0
lrwxrwxrwx 1 root root   18 4月  12 19:57 /usr/lib/x86_64-linux-gnu/libpthread.so.0 -> libpthread-2.31.so
@cdoco
Copy link
Contributor Author

cdoco commented Apr 16, 2021

#121

@lwx2615
Copy link

lwx2615 commented Apr 17, 2021

这个应该是gcc版本不对,编译要用gcc-4.8的

1 similar comment
@lwx2615
Copy link

lwx2615 commented Apr 17, 2021

这个应该是gcc版本不对,编译要用gcc-4.8的

@cdoco
Copy link
Contributor Author

cdoco commented Apr 17, 2021

@lwx2615 你看 #121 的描述 #121 (comment)

@cdoco cdoco closed this as completed Apr 21, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants