AlejandroSilvestri / osmap

Save and load orb-slam2 maps
82 stars 17 forks source link

Error during compilation with protoc #6

Closed Alexandre34 closed 5 years ago

Alexandre34 commented 5 years ago

Hello, First of all, thank you very much for sharing your code.

I am trying to compile osmap using the instructions given on the readme, however the following error appears. error: #error This file was generated by an older version of protoc which is incompatible with your Protocol Buffer headers. Please regenerate this file with a newer version of protoc.

I tried the tips given in an older issue with the same problem, but these don't solve it (using protoc in a separate folder) The version of protoc used is libprotoc 3.5.1, which seems to be the latest version.

Do you have an idea of how I could solve this problem? Thanks

AlejandroSilvestri commented 5 years ago

@Alexandre34 ,

In my case, in a terminal:

$ protoc --version
libprotoc 3.6.1

In my Ubuntu, protobuf is libprotobuf.so.10.0.0

protoc is the Protocol Buffers compiler, you use to compile osmap.proto generating only two C++ code files: osmap.pb.h and osmap.pb.cc . Osmap compiles with this files.

libprotobuf.so (Linux' name, some .dll in Windows) is a runtime library to actually use Protocol Buffers. May be you have installed in your system different and incompatible versions of this library. Try uninstalling and reinstalling Protocol Buffers.

Same thing happened to Shashika007 in https://github.com/AlejandroSilvestri/osmap/issues/3#issuecomment-475100105

I hope this help. Let me know.

Alexandre34 commented 5 years ago

Thank you for your answer, I've reinstalled Protocol buffers as explained in https://github.com/protocolbuffers/protobuf/tree/master/src, now protoc is in the version libprotoc 3.8.0. This has solved the error, so thank you ! The fact is that I was only trying to update protoc and not the whole library.

For others who may have the same problem, I suggest before reinstalling the library to uninstall protoc from the system (this seems to solve the multiple versions issue). cd /usr/local/include/ sudo rm -r google/

However, I have now an other error, but it seems to be the same as in #3 /home/ubuntu/ORB_SLAM2_GRID_MAP/include/Osmap.h:60:21: error: expected ‘)’ before ‘’ token OsmapMapPoint(Osmap); ^ /home/ubuntu/ORB_SLAM2_GRID_MAP/include/Osmap.h:70:21: error: expected ‘)’ before ‘’ token OsmapKeyFrame(Osmap); ^ I won't be able to correct it in the next few days, but I plan to investigate that afterward. Thanks

Alexandre34 commented 5 years ago

Hello, Some updates on the compilation errors.

CMakeFiles/mono_rcs.dir/Examples/Monocular/mono_rcs.cc.o: In function main': mono_rcs.cc:(.text.startup+0x249): undefined reference to ORB_SLAM2::Osmap::Osmap(ORB_SLAM2::System&)' mono_rcs.cc:(.text.startup+0xf48): undefined reference to ORB_SLAM2::Osmap::mapSave(std::__cxx11::basic_string<char, std::char_traits, std::allocator >, bool)' collect2: error: ld returned 1 exit status which I solved by adding src/Osmap.cpp and src/osmap.pb.cc in add_library in CMakeLists.txt

/home/ubuntu/ORB_SLAM2_GRID_MAP/include/osmap.pb.h:247:46: error: ‘CachedSize’ in namespace ‘google::protobuf::internal’ does not name a type mutable ::PROTOBUF_NAMESPACE_ID::internal::CachedSize _cachedsize; ^ /home/ubuntu/ORB_SLAM2_GRID_MAP/include/osmap.pb.h:145:53: error: ‘static const google::protobuf::Reflection SerializedDescriptor::GetReflection()’ cannot be declared static const ::PROTOBUF_NAMESPACE_ID::Reflection GetReflection() { ^ In file included from /home/ubuntu/anaconda3/include/google/protobuf/generated_message_reflection.h:48:0, from /home/ubuntu/ORB_SLAM2_GRID_MAP/include/osmap.pb.h:30, from /home/ubuntu/ORB_SLAM2_GRID_MAP/src/osmap.pb.cc:4: /home/ubuntu/anaconda3/include/google/protobuf/message.h:342:29: error: since ‘virtual const Reflection google::protobuf::Message::GetReflection() const’ declared in base class virtual const Reflection GetReflection() const PROTOBUF_FINAL { ^ In file included from /home/ubuntu/ORB_SLAM2_GRID_MAP/src/osmap.pb.cc:4:0: /home/ubuntu/ORB_SLAM2_GRID_MAP/include/osmap.pb.h:191:35: error: ‘google::protobuf::uint8 SerializedDescriptor::InternalSerializeWithCachedSizesToArray(google::protobuf::uint8) const’ marked ‘final’, but is not virtual

So either I compile with the wrong version or there is something fundamentaly wrong with my installation of protobuf (anaconda is also installed in my system) What is your take on this? Thanks

AlejandroSilvestri commented 5 years ago

Hi @Alexandre34 ,

class Osmap declaration added. Thank you.

I usually compile from Eclipse IDE, and it works. I'm interested in your CMakeLists.txt modifications to share with other. You mean ORB-SLAM2 CMakeLists.txt, right?

Check out new readme.md title "Adding Osmap with cmake", and please help me to make it run.

add_library( ...

src/Osmap.cpp
src/osmap.pb.cc

)

I'm not sure about ${PROTOBUF_INCLUDE_DIR}. osmap.pb.cc include protobuf headers like this:

#include <google/protobuf/stubs/common.h>

using a long path that in my Ubuntu starts in usr/local/include. I don't see where (or if) cmake look for headers in that directory. That's where opencv is, for example.

protobuf library is needed. May be declared in target_link_libraries

/usr/local/lib/libprotobuf.so

or some

$(PROTOBUF_LIBS)

I'm guessing here, I don't know how cmake finds out PROTOBUF_LIBS value. As I said, CMake is not my strength.

After it works, it would be great to have osmap code in its own directory and reference it in cmakelists.txt, with something like OSMAP_SOURCE_DIR and OSMAP_INCLUDE_DIR.

Alexandre34 commented 5 years ago

Hi @AlejandroSilvestri

Here is my CMakeLists.txt


cmake_minimum_required(VERSION 2.8) project(ORB_SLAM2)

IF(NOT CMAKE_BUILD_TYPE) SET(CMAKE_BUILD_TYPE Release) ENDIF()

MESSAGE("Build type: " ${CMAKE_BUILD_TYPE})

set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -O3 -march=native ") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -O3 -march=native")

Check C++11 or C++0x support

include(CheckCXXCompilerFlag) CHECK_CXX_COMPILER_FLAG("-std=c++11" COMPILER_SUPPORTS_CXX11) CHECK_CXX_COMPILER_FLAG("-std=c++0x" COMPILER_SUPPORTS_CXX0X) if(COMPILER_SUPPORTS_CXX11) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") add_definitions(-DCOMPILEDWITHC11) message(STATUS "Using flag -std=c++11.") elseif(COMPILER_SUPPORTS_CXX0X) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x") add_definitions(-DCOMPILEDWITHC0X) message(STATUS "Using flag -std=c++0x.") else() message(FATAL_ERROR "The compiler ${CMAKE_CXX_COMPILER} has no C++11 support. Please use a different C++ compiler.") endif()

LIST(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake_modules)

find_package(OpenCV 3.0 QUIET) if(NOT OpenCV_FOUND) find_package(OpenCV 2.4.3 QUIET) if(NOT OpenCV_FOUND) message(FATAL_ERROR "OpenCV > 2.4.3 not found.") endif() endif()

find_package(Eigen3 3.1.0 REQUIRED) find_package(Pangolin REQUIRED)

INCLUDE(FindProtobuf)

FIND_PACKAGE(Protobuf REQUIRED)

include_directories( ${PROJECT_SOURCE_DIR} ${PROJECT_SOURCE_DIR}/include ${EIGEN3_INCLUDE_DIR} ${Pangolin_INCLUDE_DIRS} ${CMAKE_CURRENT_BINARY_DIR} ${PROTOBUF_INCLUDE_DIR}

${PCL_INCLUDE_DIRS}

)

set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/lib)

add_library(${PROJECT_NAME} SHARED src/System.cc src/Tracking.cc src/LocalMapping.cc src/LoopClosing.cc src/ORBextractor.cc src/ORBmatcher.cc src/FrameDrawer.cc src/Converter.cc src/MapPoint.cc src/KeyFrame.cc src/Map.cc src/MapDrawer.cc src/Optimizer.cc src/PnPsolver.cc src/Frame.cc src/KeyFrameDatabase.cc src/Sim3Solver.cc src/Initializer.cc src/Viewer.cc src/Osmap.cpp src/osmap.pb.cc )

target_link_libraries(${PROJECT_NAME} ${OpenCV_LIBS} ${EIGEN3_LIBS} ${Pangolin_LIBRARIES} ${PROJECT_SOURCE_DIR}/Thirdparty/DBoW2/lib/libDBoW2.so ${PROJECT_SOURCE_DIR}/Thirdparty/g2o/lib/libg2o.so ${PROTOBUF_LIBRARIES} -lprotobuf )

Build examples

set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/Examples/RGB-D)

add_executable(rgbd_tum Examples/RGB-D/rgbd_tum.cc) target_link_libraries(rgbd_tum ${PROJECT_NAME})

set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/Examples/Stereo)

add_executable(stereo_kitti Examples/Stereo/stereo_kitti.cc) target_link_libraries(stereo_kitti ${PROJECT_NAME})

add_executable(stereo_euroc Examples/Stereo/stereo_euroc.cc) target_link_libraries(stereo_euroc ${PROJECT_NAME})

set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/Examples/Monocular)

add_executable(mono_rcs Examples/Monocular/mono_rcs.cc) target_link_libraries(mono_rcs ${PROJECT_NAME} ${PCL_COMMON_LIBRARIES} ${PCL_IO_LIBRARIES})

add_executable(mono_tum Examples/Monocular/mono_tum.cc) target_link_libraries(mono_tum ${PROJECT_NAME})

add_executable(mono_kitti Examples/Monocular/mono_kitti.cc) target_link_libraries(mono_kitti ${PROJECT_NAME})

add_executable(mono_euroc Examples/Monocular/mono_euroc.cc) target_link_libraries(mono_euroc ${PROJECT_NAME})


I tried reinstalling anaconda and protobuf, but it doesn't seem to solve the issue. I think I will do a clean install of Ubuntu to be sure that it is not a library compatibility issue.

AlejandroSilvestri commented 5 years ago

@Alexandre34

I just update readme.md, while reading cmake documentation. I see you already did what I say in step 5 "Compile with cmake".

In target_link_libraries you don't need -lprotobuf, it's already in ${PROTOBUF_LIBRARIES}.

If you reinstall protocol buffers, make sure you also install protoc. You need protoc and libprotobuf.so to belong to the same version of protocol buffers (although I think each one has its own different version numbers).

Usually libprotobuf.so is in usr/local/lib

After installing protocol buffers, run protoc to generate osmap.pb.cc and osmap.pb..h. Put them in the include directory, then run cmake.

cmake will say something like

-- Found Protobuf: /usr/local/lib/libprotobuf.so;-lpthread (found version "3.6.1") 

I'm aware you may already know and did all this, I writing this just in case, and for casual users reading this issue.

Alexandre34 commented 5 years ago

Hi @AlejandroSilvestri That's it ! It works !

The culprit was anaconda which installed an other version of protobuf. So I deleted it and of course cmake was lost because it was trying to found libprotobuf.so in anaconda. What I did is that I manually linked the library in target_link_library to the location in the disk (for me /usr/local/lib/libprotobuf.so) and not using ${PROTOBUF_LIBRARIES} or ${PROTOBUF_INCLUDE_DIR} (because it was linking to the wrong directory).

I'm linking here my CMakeLists.txt


cmake_minimum_required(VERSION 2.8) project(ORB_SLAM2)

IF(NOT CMAKE_BUILD_TYPE) SET(CMAKE_BUILD_TYPE Release) ENDIF()

MESSAGE("Build type: " ${CMAKE_BUILD_TYPE})

set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -O3 -march=native ") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -O3 -march=native")

Check C++11 or C++0x support

include(CheckCXXCompilerFlag) CHECK_CXX_COMPILER_FLAG("-std=c++11" COMPILER_SUPPORTS_CXX11) CHECK_CXX_COMPILER_FLAG("-std=c++0x" COMPILER_SUPPORTS_CXX0X) if(COMPILER_SUPPORTS_CXX11) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") add_definitions(-DCOMPILEDWITHC11) message(STATUS "Using flag -std=c++11.") elseif(COMPILER_SUPPORTS_CXX0X) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x") add_definitions(-DCOMPILEDWITHC0X) message(STATUS "Using flag -std=c++0x.") else() message(FATAL_ERROR "The compiler ${CMAKE_CXX_COMPILER} has no C++11 support. Please use a different C++ compiler.") endif()

LIST(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake_modules)

find_package(OpenCV 3.0 QUIET) if(NOT OpenCV_FOUND) find_package(OpenCV 2.4.3 QUIET) if(NOT OpenCV_FOUND) message(FATAL_ERROR "OpenCV > 2.4.3 not found.") endif() endif()

find_package(Eigen3 3.1.0 REQUIRED) find_package(Pangolin REQUIRED)

set(CMAKE_MODULE_PATH /home/ubuntu/protobuf/cmake )

include(FindProtobuf) find_package(Protobuf REQUIRED) if(NOT PROTOBUF_FOUND) message(FATAL_ERROR "Protocol Buffers not found.") endif()

include_directories( ${PROJECT_SOURCE_DIR} ${PROJECT_SOURCE_DIR}/include ${EIGEN3_INCLUDE_DIR} ${Pangolin_INCLUDE_DIRS} ${CMAKE_CURRENT_BINARY_DIR}

${PCL_INCLUDE_DIRS}

)

set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/lib)

add_library(${PROJECT_NAME} SHARED src/System.cc src/Tracking.cc src/LocalMapping.cc src/LoopClosing.cc src/ORBextractor.cc src/ORBmatcher.cc src/FrameDrawer.cc src/Converter.cc src/MapPoint.cc src/KeyFrame.cc src/Map.cc src/MapDrawer.cc src/Optimizer.cc src/PnPsolver.cc src/Frame.cc src/KeyFrameDatabase.cc src/Sim3Solver.cc src/Initializer.cc src/Viewer.cc src/Osmap.cpp src/osmap.pb.cc )

target_link_libraries(${PROJECT_NAME} ${OpenCV_LIBS} ${EIGEN3_LIBS} ${Pangolin_LIBRARIES} ${PROJECT_SOURCE_DIR}/Thirdparty/DBoW2/lib/libDBoW2.so ${PROJECT_SOURCE_DIR}/Thirdparty/g2o/lib/libg2o.so /usr/local/lib/libprotobuf.so )

Build examples

set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/Examples/RGB-D)

add_executable(rgbd_tum Examples/RGB-D/rgbd_tum.cc) target_link_libraries(rgbd_tum ${PROJECT_NAME})

set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/Examples/Stereo)

add_executable(stereo_kitti Examples/Stereo/stereo_kitti.cc) target_link_libraries(stereo_kitti ${PROJECT_NAME})

add_executable(stereo_euroc Examples/Stereo/stereo_euroc.cc) target_link_libraries(stereo_euroc ${PROJECT_NAME})

set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/Examples/Monocular)

add_executable(mono_rcs Examples/Monocular/mono_rcs.cc) target_link_libraries(mono_rcs ${PROJECT_NAME} ${PCL_COMMON_LIBRARIES} ${PCL_IO_LIBRARIES})

add_executable(mono_tum Examples/Monocular/mono_tum.cc) target_link_libraries(mono_tum ${PROJECT_NAME})

add_executable(mono_kitti Examples/Monocular/mono_kitti.cc) target_link_libraries(mono_kitti ${PROJECT_NAME})

add_executable(mono_euroc Examples/Monocular/mono_euroc.cc) target_link_libraries(mono_euroc ${PROJECT_NAME})


With this version, I think that we shouldn't have anymore linking issues, because it is directly linking to the right location for the library. Everything now compiles as it should and it is generating the map (in .yaml) as it should.

I still want to investigate more on these issues (because I'm clearly not a cmake expert) and trying to better integrate ORB_SLAM2 with osmap. Thanks again for your help

AlejandroSilvestri commented 5 years ago

@Alexandre34 , great, and now we have osmap on cmake. Thank you.