用#include <ixwebsocket/IXWebSocket.h> ix::WebSocket webSocket;时编译报错/usr/bin/ld: /usr/local/lib/libprotobuf.so: undefined reference to symbol 'inflateEnd' /usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libz.so: error adding symbols: DSO missing from command line collect2: error: ld returned 1 exit status t3/CMakeFiles/t3_node.dir/build.make:319: 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....
时间: 2023-07-08 21:40:51 浏览: 216
这个错误是因为在链接时找不到 zlib 库的符号,应该在编译时加入 zlib 库的链接选项。你可以在 CMakeLists.txt 中添加以下语句:
```
find_package(ZLIB REQUIRED)
target_link_libraries(your_target_name ${ZLIB_LIBRARIES})
```
其中 `your_target_name` 是你要编译的目标名称。如果你已经包含了 `ZLIB` 库的头文件目录,可以使用 `ZLIB_INCLUDE_DIRS` 变量来指定头文件目录。
```
include_directories(${ZLIB_INCLUDE_DIRS})
```
这样应该就能解决这个问题了。
相关问题
#0 Homer::RtpSessionState::deprovisionAtDestruction (this=0x7f1fe00e7650) at ../components/mos/state/session_state/src/rtp_session_state.cpp:886 886 ../components/mos/state/session_state/src/rtp_session_state.cpp: No such file or directory. [Current thread is 1 (Thread 0x7f1ffffff700 (LWP 372))] (gdb) bt #0 Homer::RtpSessionState::deprovisionAtDestruction (this=0x7f1fe00e7650) at ../components/mos/state/session_state/src/rtp_session_state.cpp:886 #1 0x00005653759a8e33 in Homer::DeviceState::~DeviceState (this=0x7f1fe00ecf50) at ../components/mos/state/device_state/src/device_state.cpp:87 #2 0x0000565375c4229e in std::_Sp_counted_base<(__gnu_cxx::_Lock_policy)2>::_M_release (this=0x7f1fe00ecf40) at /usr/bin/../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/bits/shared_ptr_base.h:155 #3 std::__shared_count<(__gnu_cxx::_Lock_policy)2>::~__shared_count (this=0x7f1fe00bbb08) at /usr/bin/../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/bits/shared_ptr_base.h:730 #4 std::__shared_ptr<Homer::DeviceStateBase, (__gnu_cxx::_Lock_policy)2>::~__shared_ptr (this=0x7f1fe00bbb00) at /usr/bin/../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/bits/shared_ptr_base.h:1169 #5 Homer::Device::~Device (this=0x7f1fe00bb070) at ../components/mos/device/src/device.cpp:94 #6 0x0000565375c3c08a in Homer::WebsocketDevice::~WebsocketDevice (this=0x7f1fe00bb070) at ../components/mos/device/src/websocket_device.h:31 #7 Homer::WebsocketClientDevice::~WebsocketClientDevice (this=0x7f1fe00bb070) at ../components/mos/device/src/websocket_client_device.cpp:20
这是一个程序崩溃的调试信息,使用了gdb进行调试。根据backtrace可以看出,程序崩溃的位置在`Homer::RtpSessionState::deprovisionAtDestruction()`函数内,该函数位于`../components/mos/state/session_state/src/rtp_session_state.cpp`文件的第886行。崩溃的原因可能是访问了不存在的文件或目录,也有可能是访问了空指针或已经被释放的内存等问题。需要对程序进行进一步调试和分析,才能找到具体的原因和解决方案。
在ros项目中添加发送websocket wss消息的功能,修改如下代码并在CmakeLists.txt中添加依赖,实现将serialized_data发送到wss://autopilot-test.t3go.cn:443/api/v1/vehicle/push/message/LFB1FV696M2L43840。main.cpp:#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" apollo::perception::PerceptionObstacles perception_obstacles_; 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; }CMakeLists.txt:cmake_minimum_required(VERSION 3.0.2) project(t3) find_package(catkin REQUIRED COMPONENTS roscpp rospy pcl_ros std_msgs third_party ) find_package(Protobuf REQUIRED) include_directories(${Protobuf_INCLUDE_DIRS} ${CMAKE_CURRENT_BINARY_DIR}/..) find_package(Boost REQUIRED) include_directories(${Boost_INCLUDE_DIRS}) set(ixwebsocket_INCLUDE_DIR "/usr/local/include/ixwebsocket") set(ixwebsocket_LIBRARIES "/usr/local/lib/libixwebsocket.a") include_directories(${ixwebsocket_INCLUDE_DIR}) include_directories(${CATKIN_DEVEL_PREFIX}/${CATKIN_GLOBAL_INCLUDE_DESTINATION}/${PROJECT_NAME}) include_directories(${CATKIN_DEVEL_PREFIX}/${CATKIN_GLOBAL_INCLUDE_DESTINATION}/smartview) catkin_package(INCLUDE_DIRS ${PROJECT_INCLUDE_DIRS} DEPENDS ${GFLAGS_LIBRARIES} ) include_directories( ${catkin_INCLUDE_DIRS} ${PROTOBUF_INCLUDE_DIR} ${PROJECT_SOURCE_DIR}/.. ) add_executable(${PROJECT_NAME}_node src/main.cpp ) add_dependencies(${PROJECT_NAME}_node ${catkin_EXPORTED_TARGETS}) target_link_libraries(${PROJECT_NAME}_node ${catkin_LIBRARIES} ${PROTOBUF_LIBRARIES} smartview_proto ) install(TARGETS ${PROJECT_NAME}_node ARCHIVE DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION} LIBRARY DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION} RUNTIME DESTINATION ${CATKIN_GLOBAL_BIN_DESTINATION} )
你可以使用以下代码来添加发送websocket wss消息的功能,同时在CmakeLists.txt中添加依赖:
```cpp
#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 <ixwebsocket/IXWebSocket.h>
using namespace ix;
apollo::perception::PerceptionObstacles perception_obstacles_;
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);
// create a WebSocket connection
WebSocket websocket;
websocket.setTLSOptions({}); // use default options
websocket.setOnMessageCallback([](const WebSocketMessagePtr& msg) {
std::cout << "Received message: " << msg->str << std::endl;
});
websocket.setOnCloseCallback([](WebSocket& ws, const WebSocketCloseInfo& info) {
std::cout << "WebSocket closed: " << info.reason << std::endl;
});
websocket.setOnErrorCallback([](const std::error_code& ec) {
std::cout << "Error: " << ec << ", error message: " << ec.message() << std::endl;
});
websocket.connect("wss://autopilot-test.t3go.cn:443/api/v1/vehicle/push/message/LFB1FV696M2L43840");
websocket.send(serialized_data);
websocket.close();
} 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;
}
```
在CmakeLists.txt中添加以下依赖:
```
find_package(ixwebsocket REQUIRED)
target_link_libraries(${PROJECT_NAME}_node ixwebsocket)
```
注意,你需要安装ixwebsocket库以使用WebSocket功能。
阅读全文