error: ‘std::shared_ptr’ has not been declared

本文解决了一个在Ubuntu16.04环境下编译C++代码时遇到的错误,该错误与包含tr1/memory头文件有关。通过调整编译设置或使用现代标准库可以有效解决问题。

ubuntu16.04 环境下,编译C++代码出错

解决方法:

#include <tr1/memory>

 

user@YBXzuiniubi:~/Livox-SDK/build$ cmake .. make sudo make install -- main project dir: /home/user/Livox-SDK -- Configuring done -- Generating done -- Build files have been written to: /home/user/Livox-SDK/build Consolidate compiler generated dependencies of target livox_sdk_static [ 2%] Building CXX object sdk_core/CMakeFiles/livox_sdk_static.dir/src/base/thread_base.cpp.o In file included from /home/user/Livox-SDK/sdk_core/src/base/thread_base.cpp:25: /home/user/Livox-SDK/sdk_core/src/base/thread_base.h:46:8: error:shared_ptr’ in namespace ‘std’ does not name a template type 46 | std::shared_ptr<std::thread> thread_; | ^~~~~~~~~~ /home/user/Livox-SDK/sdk_core/src/base/thread_base.h:30:1: note:std::shared_ptr’ is defined in header ‘<memory>’; did you forget to ‘#include <memory>’? 29 | #include "noncopyable.h" +++ |+#include <memory> 30 | /home/user/Livox-SDK/sdk_core/src/base/thread_base.cpp: In member function ‘virtual bool livox::ThreadBase::Start()’: /home/user/Livox-SDK/sdk_core/src/base/thread_base.cpp:34:3: error: ‘thread_’ was not declared in this scope; did you mean ‘pthread_t’? 34 | thread_ = std::make_shared<std::thread>(&ThreadBase::ThreadFunc, this); | ^~~~~~~ | pthread_t /home/user/Livox-SDK/sdk_core/src/base/thread_base.cpp:34:18: error: ‘make_shared’ is not a member of ‘std’ 34 | thread_ = std::make_shared<std::thread>(&ThreadBase::ThreadFunc, this); | ^~~~~~~~~~~ /home/user/Livox-SDK/sdk_core/src/base/thread_base.cpp:26:1: note:std::make_shared’ is defined in header ‘<memory>’; did you forget to ‘#include <memory>’? 25 | #include "thread_base.h" +++ |+#include <memory> 26 | #include <thread> /home/user/Livox-SDK/sdk_core/src/base/thread_base.cpp:34:41: error: expected primary-expression before ‘>’ token 34 | thread_ = std::make_shared<std::thread>(&ThreadBase::ThreadFunc, this); | ^ /home/user/Livox-SDK/sdk_core/src/base/thread_base.cpp:34:68: error: left operand of comma operator has no effect [-Werror=unused-value] 34 | thread_ = std::make_shared<std::thread>(&ThreadBase::ThreadFunc, this); | ^~~~ /home/user/Livox-SDK/sdk_core/src/base/thread_base.cpp: In member function ‘virtual void livox::ThreadBase::Join()’: /home/user/Livox-SDK/sdk_core/src/base/thread_base.cpp:41:5: error: ‘thread_’ was not declared in this scope; did you mean ‘pthread_t’? 41 | thread_->join(); | ^~~~~~~ | pthread_t At global scope: cc1plus: note: unrecognized command-line option ‘-Wno-c++11-long-long’ may have been intended to silence earlier diagnostics cc1plus: all warnings being treated as errors make[2]: *** [sdk_core/CMakeFiles/livox_sdk_static.dir/build.make:104: sdk_core/CMakeFiles/livox_sdk_static.dir/src/base/thread_base.cpp.o] Error 1 make[1]: *** [CMakeFiles/Makefile2:242: sdk_core/CMakeFiles/livox_sdk_static.dir/all] Error 2 make: *** [Makefile:136: all] Error 2 Consolidate compiler generated dependencies of target livox_sdk_static [ 2%] Building CXX object sdk_core/CMakeFiles/livox_sdk_static.dir/src/base/thread_base.cpp.o In file included from /home/user/Livox-SDK/sdk_core/src/base/thread_base.cpp:25: /home/user/Livox-SDK/sdk_core/src/base/thread_base.h:46:8: error:shared_ptr’ in namespace ‘std’ does not name a template type 46 | std::shared_ptr<std::thread> thread_; | ^~~~~~~~~~ /home/user/Livox-SDK/sdk_core/src/base/thread_base.h:30:1: note:std::shared_ptr’ is defined in header ‘<memory>’; did you forget to ‘#include <memory>’? 29 | #include "noncopyable.h" +++ |+#include <memory> 30 | /home/user/Livox-SDK/sdk_core/src/base/thread_base.cpp: In member function ‘virtual bool livox::ThreadBase::Start()’: /home/user/Livox-SDK/sdk_core/src/base/thread_base.cpp:34:3: error: ‘thread_’ was not declared in this scope; did you mean ‘pthread_t’? 34 | thread_ = std::make_shared<std::thread>(&ThreadBase::ThreadFunc, this); | ^~~~~~~ | pthread_t /home/user/Livox-SDK/sdk_core/src/base/thread_base.cpp:34:18: error: ‘make_shared’ is not a member of ‘std’ 34 | thread_ = std::make_shared<std::thread>(&ThreadBase::ThreadFunc, this); | ^~~~~~~~~~~ /home/user/Livox-SDK/sdk_core/src/base/thread_base.cpp:26:1: note:std::make_shared’ is defined in header ‘<memory>’; did you forget to ‘#include <memory>’? 25 | #include "thread_base.h" +++ |+#include <memory> 26 | #include <thread> /home/user/Livox-SDK/sdk_core/src/base/thread_base.cpp:34:41: error: expected primary-expression before ‘>’ token 34 | thread_ = std::make_shared<std::thread>(&ThreadBase::ThreadFunc, this); | ^ /home/user/Livox-SDK/sdk_core/src/base/thread_base.cpp:34:68: error: left operand of comma operator has no effect [-Werror=unused-value] 34 | thread_ = std::make_shared<std::thread>(&ThreadBase::ThreadFunc, this); | ^~~~ /home/user/Livox-SDK/sdk_core/src/base/thread_base.cpp: In member function ‘virtual void livox::ThreadBase::Join()’: /home/user/Livox-SDK/sdk_core/src/base/thread_base.cpp:41:5: error: ‘thread_’ was not declared in this scope; did you mean ‘pthread_t’? 41 | thread_->join(); | ^~~~~~~ | pthread_t At global scope: cc1plus: note: unrecognized command-line option ‘-Wno-c++11-long-long’ may have been intended to silence earlier diagnostics cc1plus: all warnings being treated as errors make[2]: *** [sdk_core/CMakeFiles/livox_sdk_static.dir/build.make:104: sdk_core/CMakeFiles/livox_sdk_static.dir/src/base/thread_base.cpp.o] Error 1 make[1]: *** [CMakeFiles/Makefile2:242: sdk_core/CMakeFiles/livox_sdk_static.dir/all] Error 2 make: *** [Makefile:136: all] Error 2 user@YBXzuiniubi:~/Livox-SDK/build$
最新发布
09-20
/home/wuyuan/src/ros2_caogao.cpp:5:5: error: ‘rclccp’ has not been declared 5 | rclccp::init(argc,argv); | ^~~~~~ /home/wuyuan/src/ros2_caogao.cpp:6:32: error: ‘rlcpp’ was not declared in this scope; did you mean ‘rclcpp’? 6 | auto node=std::make_shared<rlcpp::Node>("cpp_node"); | ^~~~~ | rclcpp /home/wuyuan/src/ros2_caogao.cpp:6:20: error: parse error in template argument list 6 | auto node=std::make_shared<rlcpp::Node>("cpp_node"); | ^~~~~~~~~~~~~~~~~~~~~~~~ /home/wuyuan/src/ros2_caogao.cpp:6:44: error: no matching function for call to ‘make_shared<<expression error> >(const char [9])’ 6 | auto node=std::make_shared<rlcpp::Node>("cpp_node"); | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~ In file included from /usr/include/c++/13/memory:80, from /opt/ros/jazzy/include/rclcpp/rclcpp/rclcpp.hpp:169, from /home/wuyuan/src/ros2_caogao.cpp:1: /usr/include/c++/13/bits/shared_ptr.h:1005:5: note: candidate: ‘template<class _Tp, class ... _Args> std::shared_ptr<typename std::enable_if<(! std::is_array< <template-parameter-1-1> >::value), _Tp>::type> std::make_shared(_Args&& ...)’ 1005 | make_shared(_Args&&... __args) | ^~~~~~~~~~~ /usr/include/c++/13/bits/shared_ptr.h:1005:5: note: template argument deduction/substitution failed: /home/wuyuan/src/ros2_caogao.cpp:6:44: error: template argument 1 is invalid 6 | auto node=std::make_shared<rlcpp::Node>("cpp_node"); | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~ In file included from /opt/ros/jazzy/include/rclcpp/rclcpp/copy_all_parameter_values.hpp:27, from /opt/ros/jazzy/include/rclcpp/rclcpp/rclcpp.hpp:171: /home/wuyuan/src/ros2_caogao.cpp:7:5: error: template argument 1 is invalid 7 | RCLCPP_INFO(node->get_logger(),"nihao"); | ^~~~~~~~~~~ /home/wuyuan/src/ros2_
03-21
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值