c++解决 /usr/include/c++/7/thread:122:对‘pthread_create’未定义的引用

这篇博客主要探讨了在使用g++编译C++程序时遇到的链接错误,即在尝试调用pthread_create函数时出现未定义引用的问题。作者提供了标准的编译选项-g++ -std=c++11 -omain main.cpp -lpthread,强调了正确链接pthread库的重要性,并可能涉及多线程编程和Unix/Linux系统的相关内容。

解决/usr/include/c++/7/thread:122:对‘pthread_create’未定义的引用

g++ -std=c++11 -o main main.cpp -lpthread
aurora@aurora:~/rs485_static_ws$ catkin_make \ > -DCMAKE_PREFIX_PATH=/opt/ros/noetic_static \ > -DCMAKE_BUILD_TYPE=Release \ > -DBoost_USE_STATIC_LIBS=ON Base path: /home/aurora/rs485_static_ws Source space: /home/aurora/rs485_static_ws/src Build space: /home/aurora/rs485_static_ws/build Devel space: /home/aurora/rs485_static_ws/devel Install space: /home/aurora/rs485_static_ws/install #### #### Running command: "cmake /home/aurora/rs485_static_ws/src -DCMAKE_PREFIX_PATH=/opt/ros/noetic_static -DCMAKE_BUILD_TYPE=Release -DBoost_USE_STATIC_LIBS=ON -DCATKIN_DEVEL_PREFIX=/home/aurora/rs485_static_ws/devel -DCMAKE_INSTALL_PREFIX=/home/aurora/rs485_static_ws/install -G Unix Makefiles" in "/home/aurora/rs485_static_ws/build" #### CMake Warning (dev) in CMakeLists.txt: No project() command is present. The top-level CMakeLists.txt file must contain a literal, direct call to the project() command. Add a line of code such as project(ProjectName) near the top of the file, but after cmake_minimum_required(). CMake is pretending there is a "project(Project)" command on the first line. This warning is for project developers. Use -Wno-dev to suppress it. -- The C compiler identification is GNU 9.4.0 -- The CXX compiler identification is GNU 9.4.0 -- Check for working C compiler: /usr/bin/cc -- Check for working C compiler: /usr/bin/cc -- works -- Detecting C compiler ABI info -- Detecting C compiler ABI info - done -- Detecting C compile features -- Detecting C compile features - done -- Check for working CXX compiler: /usr/bin/c++ -- Check for working CXX compiler: /usr/bin/c++ -- works -- Detecting CXX compiler ABI info -- Detecting CXX compiler ABI info - done -- Detecting CXX compile features -- Detecting CXX compile features - done -- Using CATKIN_DEVEL_PREFIX: /home/aurora/rs485_static_ws/devel -- Using CMAKE_PREFIX_PATH: /opt/ros/noetic_static -- This workspace overlays: /opt/ros/noetic_static -- Found PythonInterp: /usr/bin/python3 (found suitable version "3.8.10", minimum required is "3") -- Using PYTHON_EXECUTABLE: /usr/bin/python3 -- Using Debian Python package layout -- Found PY_em: /usr/lib/python3/dist-packages/em.py -- Using empy: /usr/lib/python3/dist-packages/em.py -- Using CATKIN_ENABLE_TESTING: ON -- Call enable_testing() -- Using CATKIN_TEST_RESULTS_DIR: /home/aurora/rs485_static_ws/build/test_results -- Forcing gtest/gmock from source, though one was otherwise available. -- Found gtest sources under '/usr/src/googletest': gtests will be built -- Found gmock sources under '/usr/src/googletest': gmock will be built -- Found PythonInterp: /usr/bin/python3 (found version "3.8.10") -- Found Threads: TRUE -- Using Python nosetests: /usr/bin/nosetests3 -- catkin 0.8.12 -- BUILD_SHARED_LIBS is on -- BUILD_SHARED_LIBS is on -- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -- ~~ traversing 1 packages in topological order: -- ~~ - rs485_node -- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -- +++ processing catkin package: 'rs485_node' -- ==> add_subdirectory(rs485_node) -- Using these message generators: gencpp;geneus;genlisp;gennodejs;genpy -- Found Boost: /usr/lib/aarch64-linux-gnu/cmake/Boost-1.71.0/BoostConfig.cmake (found version "1.71.0") found components: system filesystem thread -- rs485_node: 3 messages, 0 services -- Configuring done -- Generating done -- Build files have been written to: /home/aurora/rs485_static_ws/build #### #### Running command: "make -j8 -l8" in "/home/aurora/rs485_static_ws/build" #### Scanning dependencies of target std_msgs_generate_messages_cpp Scanning dependencies of target _rs485_node_generate_messages_check_deps_DualRS485Command Scanning dependencies of target _rs485_node_generate_messages_check_deps_backangle Scanning dependencies of target std_msgs_generate_messages_lisp Scanning dependencies of target std_msgs_generate_messages_nodejs Scanning dependencies of target std_msgs_generate_messages_eus Scanning dependencies of target _rs485_node_generate_messages_check_deps_RS485Command Scanning dependencies of target std_msgs_generate_messages_py [ 0%] Built target std_msgs_generate_messages_cpp [ 0%] Built target std_msgs_generate_messages_lisp [ 0%] Built target std_msgs_generate_messages_nodejs [ 0%] Built target std_msgs_generate_messages_eus [ 0%] Built target std_msgs_generate_messages_py [ 0%] Built target _rs485_node_generate_messages_check_deps_backangle [ 0%] Built target _rs485_node_generate_messages_check_deps_DualRS485Command [ 0%] Built target _rs485_node_generate_messages_check_deps_RS485Command Scanning dependencies of target rs485_node_generate_messages_lisp Scanning dependencies of target rs485_node_generate_messages_nodejs Scanning dependencies of target rs485_node_generate_messages_py Scanning dependencies of target rs485_node_generate_messages_cpp Scanning dependencies of target rs485_node_generate_messages_eus [ 12%] Generating Javascript code from rs485_node/DualRS485Command.msg [ 12%] Generating Lisp code from rs485_node/RS485Command.msg [ 12%] Generating Lisp code from rs485_node/backangle.msg [ 16%] Generating Javascript code from rs485_node/RS485Command.msg [ 25%] Generating EusLisp code from rs485_node/RS485Command.msg [ 25%] Generating Lisp code from rs485_node/DualRS485Command.msg [ 29%] Generating Python from MSG rs485_node/RS485Command [ 33%] Generating C++ code from rs485_node/RS485Command.msg [ 41%] Generating Python from MSG rs485_node/DualRS485Command [ 41%] Generating Python from MSG rs485_node/backangle [ 45%] Generating Javascript code from rs485_node/backangle.msg [ 50%] Generating EusLisp code from rs485_node/DualRS485Command.msg [ 50%] Built target rs485_node_generate_messages_lisp [ 54%] Generating C++ code from rs485_node/DualRS485Command.msg [ 58%] Generating EusLisp code from rs485_node/backangle.msg [ 58%] Built target rs485_node_generate_messages_nodejs [ 62%] Generating EusLisp manifest code for rs485_node [ 66%] Generating C++ code from rs485_node/backangle.msg [ 70%] Generating Python msg __init__.py for rs485_node [ 70%] Built target rs485_node_generate_messages_cpp [ 70%] Built target rs485_node_generate_messages_eus [ 70%] Built target rs485_node_generate_messages_py Scanning dependencies of target rs485_node_generate_messages Scanning dependencies of target rs485_node_lib [ 70%] Built target rs485_node_generate_messages [ 75%] Building CXX object rs485_node/CMakeFiles/rs485_node_lib.dir/src/serial_port.cpp.o [ 79%] Building CXX object rs485_node/CMakeFiles/rs485_node_lib.dir/src/protocol_handler.cpp.o [ 83%] Linking CXX static library /home/aurora/rs485_static_ws/devel/lib/librs485_node_lib.a [ 83%] Built target rs485_node_lib Scanning dependencies of target angle_publisher_node Scanning dependencies of target rs485_node [ 91%] Building CXX object rs485_node/CMakeFiles/angle_publisher_node.dir/src/angle_publisher_node.cpp.o [ 91%] Building CXX object rs485_node/CMakeFiles/rs485_node.dir/src/rs485_node.cpp.o In file included from /opt/ros/noetic_static/include/ros/ros.h:40, from /home/aurora/rs485_static_ws/src/rs485_node/src/rs485_node.cpp:1: /home/aurora/rs485_static_ws/src/rs485_node/src/rs485_node.cpp: In lambda function: /home/aurora/rs485_static_ws/src/rs485_node/src/rs485_node.cpp:65:22: warning: format ‘%ld’ expects argument of type ‘long int’, but argument 9 has type ‘rs485_node::backangle_<std::allocator<void> >::_circleAngle_type’ {aka ‘unsigned int’} [-Wformat=] 65 | ROS_INFO("电机id=%d, 其单圈圈角度读数为%ld", | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 66 | m.id, m.circleAngle); | ~~~~~~~~~~~~~ | | | rs485_node::backangle_<std::allocator<void> >::_circleAngle_type {aka unsigned int} /opt/ros/noetic_static/include/ros/console.h:351:165: note: in definition of macro ‘ROSCONSOLE_PRINT_AT_LOCATION_WITH_FILTER’ 351 | ole_define_location__loc.logger_, __rosconsole_define_location__loc.level_, __FILE__, __LINE__, __ROSCONSOLE_FUNCTION__, __VA_ARGS__) | ^~~~~~~~~~~ /opt/ros/noetic_static/include/ros/console.h:390:7: note: in expansion of macro ‘ROSCONSOLE_PRINT_AT_LOCATION’ 390 | ROSCONSOLE_PRINT_AT_LOCATION(__VA_ARGS__); \ | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~ /opt/ros/noetic_static/include/ros/console.h:575:35: note: in expansion of macro ‘ROS_LOG_COND’ 575 | #define ROS_LOG(level, name, ...) ROS_LOG_COND(true, level, name, __VA_ARGS__) | ^~~~~~~~~~~~ /opt/ros/noetic_static/include/rosconsole/macros_generated.h:110:23: note: in expansion of macro ‘ROS_LOG’ 110 | #define ROS_INFO(...) ROS_LOG(::ros::console::levels::Info, ROSCONSOLE_DEFAULT_NAME, __VA_ARGS__) | ^~~~~~~ /home/aurora/rs485_static_ws/src/rs485_node/src/rs485_node.cpp:65:13: note: in expansion of macro ‘ROS_INFO’ 65 | ROS_INFO("电机id=%d, 其单圈圈角度读数为%ld", | ^~~~~~~~ /home/aurora/rs485_static_ws/src/rs485_node/src/rs485_node.cpp:65:65: note: format string is defined here 65 | ROS_INFO("电机id=%d, 其单圈圈角度读数为%ld", | ~~^ | | | long int | %d [ 95%] Linking CXX executable /home/aurora/rs485_static_ws/devel/lib/rs485_node/rs485_node [100%] Linking CXX executable /home/aurora/rs485_static_ws/devel/lib/rs485_node/angle_publisher_node /usr/bin/ld: /usr/lib/gcc/aarch64-linux-gnu/9/../../../aarch64-linux-gnu/libpthread.a(pthread_create.o): in function `allocate_stack': /build/glibc-fci4Zo/glibc-2.31/nptl/allocatestack.c:525: undefined reference to `_dl_stack_flags' /usr/bin/ld: /build/glibc-fci4Zo/glibc-2.31/nptl/allocatestack.c:525: undefined reference to `_dl_stack_flags' /usr/bin/ld: /build/glibc-fci4Zo/glibc-2.31/nptl/allocatestack.c:647: undefined reference to `_dl_stack_flags' /usr/bin/ld: /build/glibc-fci4Zo/glibc-2.31/nptl/allocatestack.c:647: undefined reference to `_dl_stack_flags' /usr/bin/ld: /usr/lib/gcc/aarch64-linux-gnu/9/../../../aarch64-linux-gnu/libpthread.a(nptl-init.o): in function `__pthread_initialize_minimal_internal': /build/glibc-fci4Zo/glibc-2.31/nptl/nptl-init.c:335: undefined reference to `_dl_pagesize' /usr/bin/ld: /build/glibc-fci4Zo/glibc-2.31/nptl/nptl-init.c:335: undefined reference to `_dl_pagesize' /usr/bin/ld: /build/glibc-fci4Zo/glibc-2.31/nptl/nptl-init.c:344: undefined reference to `_dl_pagesize' /usr/bin/ld: /build/glibc-fci4Zo/glibc-2.31/nptl/nptl-init.c:360: undefined reference to `_dl_init_static_tls' /usr/bin/ld: /build/glibc-fci4Zo/glibc-2.31/nptl/nptl-init.c:362: undefined reference to `_dl_wait_lookup_done' /usr/bin/ld: /build/glibc-fci4Zo/glibc-2.31/nptl/nptl-init.c:360: undefined reference to `_dl_init_static_tls' /usr/bin/ld: /build/glibc-fci4Zo/glibc-2.31/nptl/nptl-init.c:362: undefined reference to `_dl_wait_lookup_done' /usr/bin/ld: /usr/lib/gcc/aarch64-linux-gnu/9/../../../aarch64-linux-gnu/libpthread.a(nptl-init.o): in function `__pthread_get_minstack': /build/glibc-fci4Zo/glibc-2.31/nptl/nptl-init.c:393: undefined reference to `_dl_pagesize' /usr/bin/ld: /build/glibc-fci4Zo/glibc-2.31/nptl/nptl-init.c:393: undefined reference to `_dl_pagesize' /usr/bin/ld: /usr/lib/gcc/aarch64-linux-gnu/9/../../../aarch64-linux-gnu/libpthread.a(unwind.o): in function `_jmpbuf_sp': /build/glibc-fci4Zo/glibc-2.31/nptl/../sysdeps/aarch64/jmpbuf-offsets.h:52: undefined reference to `__pointer_chk_guard_local' /usr/bin/ld: /build/glibc-fci4Zo/glibc-2.31/nptl/../sysdeps/aarch64/jmpbuf-offsets.h:52: undefined reference to `__pointer_chk_guard_local' collect2: error: ld returned 1 exit status make[2]: *** [rs485_node/CMakeFiles/rs485_node.dir/build.make:111: /home/aurora/rs485_static_ws/devel/lib/rs485_node/rs485_node] Error 1 make[1]: *** [CMakeFiles/Makefile2:442: rs485_node/CMakeFiles/rs485_node.dir/all] Error 2 make[1]: *** Waiting for unfinished jobs.... /usr/bin/ld: /usr/lib/gcc/aarch64-linux-gnu/9/../../../aarch64-linux-gnu/libpthread.a(unwind.o): in function `_jmpbuf_sp': /build/glibc-fci4Zo/glibc-2.31/nptl/../sysdeps/aarch64/jmpbuf-offsets.h:52: undefined reference to `__pointer_chk_guard_local' /usr/bin/ld: /build/glibc-fci4Zo/glibc-2.31/nptl/../sysdeps/aarch64/jmpbuf-offsets.h:52: undefined reference to `__pointer_chk_guard_local' collect2: error: ld returned 1 exit status make[2]: *** [rs485_node/CMakeFiles/angle_publisher_node.dir/build.make:110: /home/aurora/rs485_static_ws/devel/lib/rs485_node/angle_publisher_node] Error 1 make[1]: *** [CMakeFiles/Makefile2:855: rs485_node/CMakeFiles/angle_publisher_node.dir/all] Error 2 make: *** [Makefile:141: all] Error 2 Invoking "make -j8 -l8" failed
08-04
std::_Deque_iterator<esw::SingleProcessedData, esw::SingleProcessedData&, esw::SingleProcessedData*>::_M_set_node ( __new_node=<optimized out>, this=<optimized out>) at /usr/gcc-linaro-7.3.1-2018.05-x86_64_aarch64-linux-gnu/aarch64-linux-gnu/include/c++/7.3.1/bits/stl_deque.h:257 #1 std::_Deque_iterator<esw::SingleProcessedData, esw::SingleProcessedData&, esw::SingleProcessedData*>::operator+= (__n=10, this=<synthetic pointer>) at /usr/gcc-linaro-7.3.1-2018.05-x86_64_aarch64-linux-gnu/aarch64-linux-gnu/include/c++/7.3.1/bits/stl_deque.h:219 #2 std::_Deque_iterator<esw::SingleProcessedData, esw::SingleProcessedData&, esw::SingleProcessedData*>::operator+ (__n=10, this=0xffff9002c620) at /usr/gcc-linaro-7.3.1-2018.05-x86_64_aarch64-linux-gnu/aarch64-linux-gnu/include/c++/7.3.1/bits/stl_deque.h:230 #3 std::deque<esw::SingleProcessedData, std::allocator<esw::SingleProcessedData> >::_M_reserve_elements_at_back (__n=10, this=0x0) at /usr/gcc-linaro-7.3.1-2018.05-x86_64_aarch64-linux-gnu/aarch64-linux-gnu/include/c++/7.3.1/bits/stl_deque.h:2129 #4 std::deque<esw::SingleProcessedData, std::allocator<esw::SingleProcessedData> >::_M_range_insert_aux<esw::SingleProcessedData*> ( __last=0xffff9d7eb3c0, __first=0xffff9d7eaf10, __pos=..., this=0x0) at /usr/gcc-linaro-7.3.1-2018.05-x86_64_aarch64-linux-gnu/aarch64-linux-gnu/include/c++/7.3.1/bits/deque.tcc:608 #5 std::deque<esw::SingleProcessedData, std::allocator<esw::SingleProcessedData> >::_M_insert_dispatch<esw::SingleProcessedData*> ( __last=0xffff9d7eb3c0, __first=0xffff9d7eaf10, __pos=..., this=0x0) at /usr/gcc-linaro-7.3.1-2018.05-x86_64_aarch64-linux-gnu/aarch64-linux-gnu/include/c++/7.3.1/bits/stl_deque.h:2011 #6 std::deque<esw::SingleProcessedData, std::allocator<esw::SingleProcessedData> >::insert<esw::SingleProcessedData*, void> ( __last=0xffff9d7eb3c0, __first=0xffff9d7eaf10, __position=..., this=0x0) at /usr/gcc-linaro-7.3.1-2018.05-x86_64_aarch64-linux-gnu/aarch64-linux-gnu/include/c++/7.3.1/bits/stl_deque.h:1739 #7 esw::MagTracking::SolveDoubleSensors (this=0xffff9002ae50, vecRawData=..., trackingResult=...) at /mnt/v1/wenzhao.huang/Emts-alg/BoardSoftware/Algorithm/src/emts_alg_mag_tracking.cpp:325 #8 0x0000000000436934 in esw::TerminalController::GetTrackingResult (this=this@entry=0xffff90014778, singleDataVec=..., singleUnit=false, exception=@0xffff9001bd9a: 0, location=...) at /mnt/v1/wenzhao.huang/Emts-alg/BoardSoftware/Feature/src/emts_feature_terminal_controller.cpp:198 #9 0x0000000000434d2c in esw::TrackingManager::Run (this=0xffff90013bf0) at /mnt/v1/wenzhao.huang/Emts-alg/BoardSoftware/Feature/src/emts_feature_tracking_manager.cpp:192 #10 0x0000ffffb065bf9c in ?? () from /lib/aarch64-linux-gnu/libstdc++.so.6 #11 0x0000ffffb0793624 in start_thread (arg=0xffffb065bf80) at pthread_create.c:477 #12 0x0000ffffb03d062c in thread_start () at ../sysdeps/unix/sysv/linux/aarch64/clone.S:78 分析奔溃原因
最新发布
08-26
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

肥鼠路易

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值