I try to compile some protocol-buffer files and I am getting the following errors.
[ 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
The files are in different folders. Can I trick the compiler GCC 5.4.0 so that there are not multiple definitions? The CMakeLists.txt is quite huge because I added all source files by hand. Here are some code snippets:
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}
)
while the PTB_SRC
and PTB_HDR
are the protocol-buffer sources and headers. This project is already running on windows with MS projects. Unfortunately, I don't have any CMake for that. I am also happy for ideas and guesses.