0

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.

j35t3r
  • 1,254
  • 2
  • 19
  • 53
  • Simple, but ugly trick is to add `inline` keyword to functions. This won't work with variables tho. Best solution would be to fix multiple symbol definition - change all but one definitions of every symbol to declaration and you will be fine. – Radosław Cybulski Jun 22 '19 at 20:06
  • In overall, there are 180 headers and 180 source files. I hope there will be a better solution. – j35t3r Jun 22 '19 at 20:19
  • It seems you have two proto files defining messages with the same name in the same namespace. This is, shall we say, unwise. Are you the author of these proto files? – Igor Tandetnik Jun 23 '19 at 00:07
  • It is from the Baidu Apollo project. – j35t3r Jun 23 '19 at 06:36
  • @RadosławCybulski `inline` does not work bad. – j35t3r Jun 24 '19 at 06:38

0 Answers0