stella-cv / stella_vslam_ros

ROS package for stella_vslam
https://stella-cv.rtfd.io/en/latest/
Other
117 stars 77 forks source link

Building Error with Stella VSLAM ROS: Undefined Reference to g2o Library #128

Closed AmineDh98 closed 1 year ago

AmineDh98 commented 1 year ago

Describe the bug

I am experiencing a building error related to the g2o library when trying to run the stella_vslam_ros package.

To Reproduce

Steps to reproduce the behavior:

The bag is explained below:

I am having a building error related to the g2o library when I try to run the stella_vslam_ros.

First of all, I followed the instructions and installed the stella_vslam, and it's working fine with the provided example videos using the socket viewer to visualize.

Then I followed the instructions for stella_vslam_ros installation, and when I tried to build the catkin workspace, it gave the following error:

[ 66%] Built target cv_bridge_boost
[ 77%] Linking CXX executable /home/dhem_am/catkin_ws/devel/lib/stella_vslam_ros/run_slam
/usr/bin/ld: /usr/local/lib/libstella_vslam.so: undefined reference to g2o::OptimizableGraph::Edge::clone() const
/usr/bin/ld: /usr/local/lib/libstella_vslam.so: undefined reference to g2o::OptimizableGraph::Vertex::clone() const
collect2: error: ld returned 1 exit status
make[2]: *** [stella_vslam_ros/src/CMakeFiles/run_slam.dir/build.make:381: /home/dhem_am/catkin_ws/devel/lib/stella_vslam_ros/run_slam] Error 1
make[1]: *** [CMakeFiles/Makefile2:3325: stella_vslam_ros/src/CMakeFiles/run_slam.dir/all] Error 2
make: *** [Makefile:146: all] Error 2
Invoking "make -j16 -l16" failed

I understood that the problem occurred when building the dependency with g2o. So I rebuilt the g2o and stella_vslam packages using the following commands: 1.Remove g2o:

sudo apt-get remove ros-noetic-libg2o
  1. Remove the build folder from g2o and rebuild it:
    cd /tmp/g2o 
    rm -rf build
    mkdir build && cd build
    cmake \
    -DCMAKE_BUILD_TYPE=Release \
    -DCMAKE_INSTALL_PREFIX=/usr/local \
    -DBUILD_SHARED_LIBS=ON \
    -DBUILD_UNITTESTS=OFF \
    -DG2O_USE_CHOLMOD=OFF \
    -DG2O_USE_CSPARSE=ON \
    -DG2O_USE_OPENGL=OFF \
    -DG2O_USE_OPENMP=OFF \
    -DG2O_BUILD_APPS=OFF \
    -DG2O_BUILD_EXAMPLES=OFF \
    -DG2O_BUILD_LINKED_APPS=OFF \
    ..
    make -j4 && sudo make install
  2. Repeat the same process for the stella_vslam build folder:
    cd stella_slam
    rm -rf build
    mkdir build && cd build
    cmake \
    -DUSE_STACK_TRACE_LOGGER=ON \
    -DCMAKE_BUILD_TYPE=RelWithDebInfo \
    -DUSE_PANGOLIN_VIEWER=OFF \
    -DUSE_SOCKET_PUBLISHER=ON \
    -DINSTALL_SOCKET_PUBLISHER=ON \
    -DBUILD_TESTS=OFF \
    -DBUILD_EXAMPLES=ON \
    ..
    make -j4 && sudo make install
  3. Install libg2o again:
    sudo apt-get install ros-noetic-libg2o
  4. Build the catkin workspace again:
cd catkin_ws
catkin_make -DBUILD_WITH_MARCH_NATIVE=ON -DUSE_PANGOLIN_VIEWER=OFF -DUSE_SOCKET_PUBLISHER=ON -DUSE_STACK_TRACE_LOGGER=ON -DBOW_FRAMEWORK=DBoW2 -DUSE_OPENMP=OFF

After performing these steps, the catkin workspace built successfully, and catkin was able to find the dependencies.

Then I tested stella_slam_ros by publishing a video to the topic "/camera/image_raw" and running:

rosrun stella_vslam_ros run_slam -v ./orb_vocab.fbow -c ./equirectangular.yaml --map-db-out map.msg

However, I encountered the following error:

/home/dhem_am/catkin_ws/devel/lib/stella_vslam_ros/run_slam: symbol lookup error: /usr/local/lib/libstella_vslam.so: undefined symbol: _ZN3g2o7csparse7CSparseC1Ev

To solve this, I rebuilt the stella_vslam folder again by removing the build folder and rebuilding it. After this step, it worked, and I was able to visualize the video and see the vslam working in the socket viewer.

The problem now is that if I build the catkin workspace again, it will give the same error:

/usr/bin/ld: /usr/local/lib/libstella_vslam.so: undefined reference to g2o::OptimizableGraph::Edge::clone() const
/usr/bin/ld: /usr/local/lib/libstella_vslam.so: undefined reference to g2o::OptimizableGraph::Vertex::clone() const
collect2: error: ld returned 1 exit status
make[2]: *** [stella_vslam_ros/src/CMakeFiles/run_slam.dir/build.make:381: /home/dhem_am/catkin_ws/devel/lib/stella_vslam_ros/run_slam] Error 1
make[1]: *** [CMakeFiles/Makefile2:3325: stella_vslam_ros/src/CMakeFiles/run_slam.dir/all] Error 2
make: *** [Makefile:146: all] Error 2
Invoking "make -j16 -l16" failed

Expected behavior

I expected the catkin workspace to build successfully without any errors.

Environment

Additional context

So, my question is: Is there any way to solve this error and avoid having to repeat the steps to rebuild the catkin_ws and encountering the undefined symbol: _ZN3g2o7csparse7CSparseC1Ev error?

Thank you.

ymd-stella commented 1 year ago

Did not reproduce. Please describe the complete and correct reproduction procedure.

ymd-stella commented 1 year ago

@AmineDh98 Please refer to the updated documentation. https://stella-cv.readthedocs.io/en/latest/ros_package.html#installation

If you are not familiar with Linux, you should stop using WSL and use Native Ubuntu. Only SocketViewer is available in WSL for visualization, but PangolinViewer has more features.