ROS 打包报错 /usr/bin/ld: cannot find -lpthreads

完整日志如下:

Performing C SOURCE FILE Test CMAKE_HAVE_LIBC_PTHREAD failed with the following output:
Change Dir: /home/smile/packTest/src/duigaoche_ws/src/component/circular_hole_detection_generalization/.obj-x86_64-linux-gnu/CMakeFiles/CMakeTmp

Run Build Command(s):/usr/bin/make cmTC_1713e/fast && make[2]: Entering directory '/home/smile/packTest/src/duigaoche_ws/src/component/circular_hole_detection_generalization/.obj-x86_64-linux-gnu/CMakeFiles/CMakeTmp'
/usr/bin/make -f CMakeFiles/cmTC_1713e.dir/build.make CMakeFiles/cmTC_1713e.dir/build
make[3]: Entering directory '/home/smile/packTest/src/duigaoche_ws/src/component/circular_hole_detection_generalization/.obj-x86_64-linux-gnu/CMakeFiles/CMakeTmp'
Building C object CMakeFiles/cmTC_1713e.dir/src.c.o
/usr/bin/cc   -g -O2 -fdebug-prefix-map=/home/smile/packTest/src/duigaoche_ws/src/component/circular_hole_detection_generalization=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -DCMAKE_HAVE_LIBC_PTHREAD   -o CMakeFiles/cmTC_1713e.dir/src.c.o   -c /home/smile/packTest/src/duigaoche_ws/src/component/circular_hole_detection_generalization/.obj-x86_64-linux-gnu/CMakeFiles/CMakeTmp/src.c
Linking C executable cmTC_1713e
/usr/bin/cmake -E cmake_link_script CMakeFiles/cmTC_1713e.dir/link.txt --verbose=1
/usr/bin/cc -g -O2 -fdebug-prefix-map=/home/smile/packTest/src/duigaoche_ws/src/component/circular_hole_detection_generalization=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -DCMAKE_HAVE_LIBC_PTHREAD    -rdynamic CMakeFiles/cmTC_1713e.dir/src.c.o  -o cmTC_1713e 
/usr/bin/ld: CMakeFiles/cmTC_1713e.dir/src.c.o: in function `main':
./.obj-x86_64-linux-gnu/CMakeFiles/CMakeTmp/./.obj-x86_64-linux-gnu/CMakeFiles/CMakeTmp/src.c:11: undefined reference to `pthread_create'
/usr/bin/ld: ./.obj-x86_64-linux-gnu/CMakeFiles/CMakeTmp/./.obj-x86_64-linux-gnu/CMakeFiles/CMakeTmp/src.c:12: undefined reference to `pthread_detach'
/usr/bin/ld: ./.obj-x86_64-linux-gnu/CMakeFiles/CMakeTmp/./.obj-x86_64-linux-gnu/CMakeFiles/CMakeTmp/src.c:13: undefined reference to `pthread_join'
collect2: error: ld returned 1 exit status
make[3]: *** [CMakeFiles/cmTC_1713e.dir/build.make:87: cmTC_1713e] Error 1
make[3]: Leaving directory '/home/smile/packTest/src/duigaoche_ws/src/component/circular_hole_detection_generalization/.obj-x86_64-linux-gnu/CMakeFiles/CMakeTmp'
make[2]: *** [Makefile:121: cmTC_1713e/fast] Error 2
make[2]: Leaving directory '/home/smile/packTest/src/duigaoche_ws/src/component/circular_hole_detection_generalization/.obj-x86_64-linux-gnu/CMakeFiles/CMakeTmp'


Source file was:
#include 

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: /home/smile/packTest/src/duigaoche_ws/src/component/circular_hole_detection_generalization/.obj-x86_64-linux-gnu/CMakeFiles/CMakeTmp

Run Build Command(s):/usr/bin/make cmTC_e70f0/fast && make[2]: Entering directory '/home/smile/packTest/src/duigaoche_ws/src/component/circular_hole_detection_generalization/.obj-x86_64-linux-gnu/CMakeFiles/CMakeTmp'
/usr/bin/make -f CMakeFiles/cmTC_e70f0.dir/build.make CMakeFiles/cmTC_e70f0.dir/build
make[3]: Entering directory '/home/smile/packTest/src/duigaoche_ws/src/component/circular_hole_detection_generalization/.obj-x86_64-linux-gnu/CMakeFiles/CMakeTmp'
Building C object CMakeFiles/cmTC_e70f0.dir/CheckFunctionExists.c.o
/usr/bin/cc   -g -O2 -fdebug-prefix-map=/home/smile/packTest/src/duigaoche_ws/src/component/circular_hole_detection_generalization=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -DCHECK_FUNCTION_EXISTS=pthread_create   -o CMakeFiles/cmTC_e70f0.dir/CheckFunctionExists.c.o   -c /usr/share/cmake-3.16/Modules/CheckFunctionExists.c
Linking C executable cmTC_e70f0
/usr/bin/cmake -E cmake_link_script CMakeFiles/cmTC_e70f0.dir/link.txt --verbose=1
/usr/bin/cc -g -O2 -fdebug-prefix-map=/home/smile/packTest/src/duigaoche_ws/src/component/circular_hole_detection_generalization=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -DCHECK_FUNCTION_EXISTS=pthread_create    -rdynamic CMakeFiles/cmTC_e70f0.dir/CheckFunctionExists.c.o  -o cmTC_e70f0  -lpthreads 
/usr/bin/ld: cannot find -lpthreads
collect2: error: ld returned 1 exit status
make[3]: *** [CMakeFiles/cmTC_e70f0.dir/build.make:87: cmTC_e70f0] Error 1
make[3]: Leaving directory '/home/smile/packTest/src/duigaoche_ws/src/component/circular_hole_detection_generalization/.obj-x86_64-linux-gnu/CMakeFiles/CMakeTmp'
make[2]: *** [Makefile:121: cmTC_e70f0/fast] Error 2
make[2]: Leaving directory '/home/smile/packTest/src/duigaoche_ws/src/component/circular_hole_detection_generalization/.obj-x86_64-linux-gnu/CMakeFiles/CMakeTmp'



dh_auto_configure: error: cd .obj-x86_64-linux-gnu && cmake -DCMAKE_INSTALL_PREFIX=/usr -DCMAKE_BUILD_TYPE=None -DCMAKE_INSTALL_SYSCONFDIR=/etc -DCMAKE_INSTALL_LOCALSTATEDIR=/var -DCMAKE_EXPORT_NO_PACKAGE_REGISTRY=ON -DCMAKE_FIND_PACKAGE_NO_PACKAGE_REGISTRY=ON "-GUnix Makefiles" -DCMAKE_VERBOSE_MAKEFILE=ON -DCMAKE_AUTOGEN_VERBOSE=ON -DCMAKE_INSTALL_LIBDIR=lib/x86_64-linux-gnu -DCATKIN_BUILD_BINARY_PACKAGE=1 -DCMAKE_INSTALL_PREFIX=/opt/ros/noetic -DCMAKE_PREFIX_PATH=/opt/ros/noetic .. returned exit code 1
make[1]: *** [debian/rules:33: override_dh_auto_configure] Error 255
make[1]: Leaving directory '/home/smile/packTest/src/duigaoche_ws/src/component/circular_hole_detection_generalization'
make: *** [debian/rules:27: binary] Error 2

原因

在进行动态参数配置时添加了add_dependencies(circular_hole_detection_generalization_node ${PROJECT_NAME}_gencfg) 节点名字与实际名字不符, 实际应该添加的是add_dependencies(circular_hole_detection_node ${PROJECT_NAME}_gencfg) # Added line , 配置的名字不一样竟然会导致线程配置错误!
好烦啊! 一直在找线程库在哪里出了问题!!!
写CMakelist一定要注意名字的配置!!!
不要直接复制粘贴, 可能有坑!

你可能感兴趣的:(机器人,c++)