编译报错如下:CMakeFiles/t3_node.dir/src/main.cpp.o: In function `boost::asio::ssl::detail::openssl_init_base::do_init::~do_init()': main.cpp:(.text._ZN5boost4asio3ssl6detail17openssl_init_base7do_initD2Ev[_ZN5boost4asio3ssl6detail17openssl_init_base7do_initD5Ev]+0x12): undefined reference to `CONF_modules_unload' CMakeFiles/t3_node.dir/src/main.cpp.o: In function `boost::asio::error::detail::ssl_category::message[abi:cxx11](int) const': main.cpp:(.text._ZNK5boost4asio5error6detail12ssl_category7messageB5cxx11Ei[_ZNK5boost4asio5error6detail12ssl_category7messageB5cxx11Ei]+0x2c): undefined reference to `ERR_reason_error_string' main.cpp:(.text._ZNK5boost4asio5error6detail12ssl_category7messageB5cxx11Ei[_ZNK5boost4asio5error6detail12ssl_category7messageB5cxx11Ei]+0x48): undefined reference to `ERR_lib_error_string' main.cpp:(.text._ZNK5boost4asio5error6detail12ssl_category7messageB5cxx11Ei[_ZNK5boost4asio5error6detail12ssl_category7messageB5cxx11Ei]+0x59): undefined reference to `ERR_func_error_string' collect2: error: ld returned 1 exit status t3/CMakeFiles/t3_node.dir/build.make:318: recipe for target '/smartview/devel/lib/t3/t3_node' failed make[2]: *** [/smartview/devel/lib/t3/t3_node] Error 1 CMakeFiles/Makefile2:3555: recipe for target 't3/CMakeFiles/t3_node.dir/all' failed make[1]: *** [t3/CMakeFiles/t3_node.dir/all] Error 2 make[1]: *** Waiting for unfinished jobs.... [ 96%] Built target play_node [100%] Built target smartview_handler Makefile:145: recipe for target 'all' failed make: *** [all] Error 2 Invoking "make -j20 -l20" failed
时间: 2024-03-16 17:41:33 浏览: 248
这个错误提示表明在链接时找不到OpenSSL库。你可以尝试在CMakeLists.txt文件中添加链接OpenSSL库的代码,如下所示:
```
find_package(OpenSSL REQUIRED)
target_link_libraries(your_project_name OpenSSL::SSL OpenSSL::Crypto)
```
其中,your_project_name是你的项目名。这个代码片段会在链接你的项目时添加OpenSSL库。如果仍然无法解决问题,你可以检查一下OpenSSL库是否正确安装并且库的路径是否正确添加到系统路径中。
相关问题
帮我修改下面的代码。要求建立一次weboscket链接,链接到wss://autopilot-test.t3go.cn:443/api/v1/vehicle/push/message/LFB1FV696M2L43840,当订阅到感知话题调用perceptionCallback时,通过wss发送serialized_data:#include "ros/ros.h" #include "std_msgs/String.h" #include <boost/thread/locks.hpp> #include <boost/thread/shared_mutex.hpp> #include "third_party/apollo/proto/perception/perception_obstacle.pb.h" #include "t3_perception.pb.h" #include <iostream> #include <websocketpp/config/asio_client.hpp> #include <websocketpp/client.hpp> #include <websocketpp/common/thread.hpp> apollo::perception::PerceptionObstacles perception_obstacles_; typedef websocketpp::clientwebsocketpp::config::asio_tls_client client; void perceptionCallback(const std_msgs::String& msg) { ROS_WARN("t3 perceptionCallback parse"); if (perception_obstacles_.ParseFromString(msg.data)) { double timestamp = perception_obstacles_.header().timestamp_sec(); ROS_INFO("t3 perceptionCallback timestamp %f count:%d", timestamp, perception_obstacles_.perception_obstacle().size()); std::string data; perception_obstacles_.SerializeToString(&data); VehData veh_data; veh_data.set_messagetype(5); veh_data.set_messagedes("PerceptionObstacles"); veh_data.set_contents(data); std::string serialized_data; veh_data.SerializeToString(&serialized_data); } else { ROS_ERROR("t3 perceptionCallback parse fail!"); } } int main(int argc, char **argv) { ros::init(argc, argv, "listener"); ros::NodeHandle n; ros::Subscriber sub = n.subscribe("/perception_node/perception_objects", 1000, perceptionCallback); ros::spin(); return 0; }
好的,这里是修改后的代码:
```c++
#include "ros/ros.h"
#include "std_msgs/String.h"
#include <boost/thread/locks.hpp>
#include <boost/thread/shared_mutex.hpp>
#include "third_party/apollo/proto/perception/perception_obstacle.pb.h"
#include "t3_perception.pb.h"
#include <iostream>
#include <websocketpp/config/asio_client.hpp>
#include <websocketpp/client.hpp>
#include <websocketpp/common/thread.hpp>
using namespace std;
apollo::perception::PerceptionObstacles perception_obstacles_;
typedef websocketpp::client<websocketpp::config::asio_tls_client> client;
void perceptionCallback(const std_msgs::String& msg, client* c) {
ROS_WARN("t3 perceptionCallback parse");
if (perception_obstacles_.ParseFromString(msg.data)) {
double timestamp = perception_obstacles_.header().timestamp_sec();
ROS_INFO("t3 perceptionCallback timestamp %f count:%d", timestamp, perception_obstacles_.perception_obstacle().size());
std::string data;
perception_obstacles_.SerializeToString(&data);
VehData veh_data;
veh_data.set_messagetype(5);
veh_data.set_messagedes("PerceptionObstacles");
veh_data.set_contents(data);
std::string serialized_data;
veh_data.SerializeToString(&serialized_data);
try {
c->send(serialized_data);
} catch (const websocketpp::exception& e) {
ROS_ERROR("t3 perceptionCallback send failed: %s", e.what());
}
} else {
ROS_ERROR("t3 perceptionCallback parse fail!");
}
}
int main(int argc, char **argv) {
ros::init(argc, argv, "listener");
ros::NodeHandle n;
ros::Subscriber sub = n.subscribe("/perception_node/perception_objects", 1000,
boost::bind(&perceptionCallback, _1, new client()));
client* c = sub.getCallbackQueue()->getCallbackThread().get_context<client>();
c->set_access_channels(websocketpp::log::alevel::none);
c->set_error_channels(websocketpp::log::elevel::none);
websocketpp::lib::error_code ec;
client::connection_ptr con = c->get_connection("wss://autopilot-test.t3go.cn:443/api/v1/vehicle/push/message/LFB1FV696M2L43840", ec);
if (ec) {
ROS_ERROR("t3 websocket connection failed: %s", ec.message().c_str());
return 1;
}
c->connect(con);
ROS_INFO("t3 websocket connected");
ros::spin();
return 0;
}
```
主要的修改包括:
1. 将 `websocketpp::clientwebsocketpp::config::asio_tls_client` 改为 `websocketpp::client<websocketpp::config::asio_tls_client>`,因为 `websocketpp` 3.0 版本后改变了类模板的定义。
2. 修改 `perceptionCallback` 函数,将 `serialized_data` 发送到 websocket 服务器。由于该函数是回调函数,需要将 client 指针作为参数传递进去,这里使用 `boost::bind` 来实现。
3. 在 `main` 函数中建立 websocket 连接,并将 client 指针传递给 `perceptionCallback` 函数。注意要将 client 的日志级别设置为 none,以避免输出过多的日志。
void NetClient::DoRead() { //开启异步循环读取 //m_Client_Socket.async_read_some(boost::asio::buffer(Buf, TCP_BUF_LEN), // boost::bind(&NetClient::OnRead, // this, // boost::asio::placeholders::error, // boost::asio::placeholders::bytes_transferred)); size_t len = m_NetBuffer.writableBytes(); if (len < 512) { len = 512; m_NetBuffer.ensureWritableBytes(len); } m_Client_Socket.async_read_some(boost::asio::buffer(m_NetBuffer.beginWrite(), len), boost::bind(&NetClient::OnRead, this, boost::asio::placeholders::error, boost::asio::placeholders::bytes_transferred)); }
这段代码是关于网络编程中异步读取的实现,使用了boost::asio库。该函数实现了异步循环读取数据,使用了m_Client_Socket.async_read_some()函数来异步读取数据,并且传递了一个回调函数OnRead()作为读取完成后的回调处理函数。在函数开始时,首先获取了当前可写入的字节数,如果小于512,则扩展缓冲区大小至512字节。然后使用m_Client_Socket.async_read_some()函数异步读取数据,并且传递了一个长度为len的缓冲区,并设置了回调函数OnRead()。
阅读全文