我尝试编译一些协议缓冲区文件,但出现以下错误。
[ 99%] Building CXX object CMakeFiles/lattice_planner.dir/modules/control/proto/lat_controller_conf.pb.cc.o
[100%] Linking CXX executable lattice_planner
CMakeFiles/lattice_planner.dir/modules/localization/proto/pose.pb.cc.o:(.bss+0x0): multiple definition of `apollo::localization::_Pose_default_instance_'
CMakeFiles/lattice_planner.dir/modules/common/localization/proto/pose.pb.cc.o:(.bss+0x0): first defined here
CMakeFiles/lattice_planner.dir/modules/localization/proto/pose.pb.cc.o: In function `apollo::localization::Pose::Pose()':
pose.pb.cc:(.text+0x4e8): multiple definition of `apollo::localization::Pose::Pose()'
CMakeFiles/lattice_planner.dir/modules/common/localization/proto/pose.pb.cc.o:pose.pb.cc:(.text+0x4e8): first defined here
文件位于不同的文件夹中。我可以欺骗编译器GCC 5.4.0,以便没有多个定义吗? CMakeLists.txt很大,因为我是手动添加所有源文件的。以下是一些代码段:
cmake_minimum_required(VERSION 3.5)
project(lattice_planner_src)
set(CMAKE_CXX_FLAGS "-Wall -std=c++11 -pthread")
find_package(Protobuf 3.7.1 REQUIRED)
if(PROTOBUF_FOUND)
message ("log: protobuf found")
else()
message (FATAL_ERROR "Cannot find Protobuf")
endif()
add_executable(lattice_planner apollo-planner-test-main.cpp ${SOURCE_FILES} ${HEADER_FILES} ${PTB_SRC} ${PTB_HDR})
target_include_directories (
lattice_planner
PUBLIC
${Boost_INCLUDE_DIRS}
${PROJECT_SOURCE_DIR}
${PROTOBUF_INCLUDE_DIRS}
${EIGEN3_INCLUDE_DIR}
/usr/local/include/qpOASES
${TinyXML2_INCLUDE_DIR}
${IPOPT_INCLUDE_DIRS}
${GLOG_INCLUDE_DIR}
ctpl
)
target_link_libraries(lattice_planner
# EIGEN
${TinyXML2_LIBRARIES}
# ${GLOG_LIBRARY}
${IPOPT_LIBRARIES}
${Boost_LIBRARIES}
${PROTOBUF_LIBRARIES}
/usr/local/lib/libglog.so.0
/usr/local/lib/libqpOASES.a
${libgtest}
)
,而PTB_SRC
和PTB_HDR
是协议缓冲区的源和标头。该项目已经在带有MS项目的Windows上运行。不幸的是,我对此没有任何CMake。我也很高兴有想法和猜测。