我正在开发用于 CARLA 模拟的虚幻引擎 4。运行时出现未定义符号错误。以下是我的代码:
数据结构.h
#pragma once
#include <cstdint>
#include <vector>
namespace carla {
namespace sensor {
namespace s11n {
class DataStructure{
friend class LidarMeasurement;
public:
typedef struct{
uint8_t distance[2];
uint8_t reflectivity;
}data_point;
typedef struct{
uint8_t flag[2];
uint8_t Azimuth[2];
std::vector<data_point> points;
}data_block;
typedef struct{
uint8_t UDP[42];
std::vector<data_block> data;
uint32_t time_stamp;
uint16_t factory;
}data_packet;
static data_point current_data_point;
static data_block current_data_block;
static data_packet current_data_packet;
static std::vector<data_packet> packets_from_current_frame;
static uint16_t number_of_packets_this_frame;
public:
static void fill_block(float azi, float reflectivity, float distance);
static void fill_packet();
};
}
}
}
数据结构.cpp
#include<stdint.h>
#include "carla/sensor/s11n/DataStructure.h"
namespace carla {
namespace sensor {
namespace s11n {
DataStructure::data_point DataStructure::current_data_point;
DataStructure::data_block DataStructure::current_data_block;
DataStructure::data_packet DataStructure::current_data_packet;
static uint16_t block_itr = 0;
static uint16_t packet_itr = 0;
std::vector<DataStructure::data_packet> DataStructure::packets_from_current_frame;
void DataStructure::fill_block(float azi, float reflectivity, float distance){
if(block_itr == 0){
current_data_block.points.clear();
current_data_block.flag[0] = 0xFF;
current_data_block.flag[1] = 0xEE;
uint16_t azimuth = static_cast<uint16_t>(azi * 100);
current_data_block.Azimuth[1] = (azimuth & 0xFF00) >> 0x08;
current_data_block.Azimuth[0] = (azimuth & 0x00FF);
}
uint16_t dist = static_cast<uint16_t>((distance * 100)/2);
current_data_point.distance[0] = static_cast<uint8_t>(dist % 0x100);
current_data_point.distance[1] = static_cast<uint8_t>(dist / 0x100);
current_data_point.reflectivity = static_cast<uint8_t>(reflectivity * 255);
current_data_block.points.push_back(current_data_point);
block_itr ++;
if(block_itr == 32){
DataStructure::fill_packet();
block_itr = 0;
}
}
void DataStructure::fill_packet(){
if(packet_itr == 0){
current_data_packet.data.clear();
current_data_packet.factory = 0x2222;
}
current_data_packet.data.push_back(current_data_block);
packet_itr ++;
if(packet_itr == 12){
packet_itr = 0;
packets_from_current_frame.push_back(current_data_packet);
}
}
}
}
}
错误信息:
/home/carla_static/UnrealEngine_4.22/Engine/Binaries/Linux/UE4Editor: symbol lookup error: /home/carla_static/carla/Unreal/CarlaUE4/Plugins/Carla/Binaries/Linux/libUE4Editor-Carla.so: undefined symbol: _ZN5carla6sensor4s11n13DataStructure10fill_blockEfff
当我尝试在课堂上使用 fill_block 函数时会弹出此错误LidarMeasurement
。
也可以在没有cpp的情况下完成代码吗?如果可能,如何声明和定义静态变量?
我执行了以下步骤:
- 添加了 .cpp 和 .h 文件(没有错误
make Libcarla.Client.Debug
) - 添加文件后,我删除了二进制文件并
make rebuild
构建了所有模块 - 启动 UE4 (make launch) 并运行 python 客户端
我正在使用 - Ubuntu:18.04 - Carla 0.9.6 - UE 4.22