introlab / rtabmap_ros

RTAB-Map's ROS package.
http://wiki.ros.org/rtabmap_ros
BSD 3-Clause "New" or "Revised" License
1.01k stars 558 forks source link

Can't build from source : WifiSignalSubNode.cpp undefined reference to rtabmap::util3d::transformPointCloud #1238

Open GiannisSp opened 5 days ago

GiannisSp commented 5 days ago

I am trying to build rtabmap & rtabmap-ros from source, because I want CUDA support RTAB map docker, that for now I'm testing it on native Ubuntu20.04. As far as rtabmap everything works, without building errors. RTABmap & RTABmap-ros version 0.21.5-noetic VTK version 9.4 ( tried 7.1 too ) PCL version 1.14.1 (without the -march=native flag)(tried down to 1.11) [ can't test 1.10 'cause I don't have the right GPU ] Boost version 1.71 OpenCV version : latest 4.x ROS : Noetic , Ubuntu 20.04 (docker) Tried different GCC/G++ [ v11, v8 ]

Any help would be much appreciated. I've struggled for days on these and past problems Note: I am not planning to use directly WiFi capabilities (if any), so disabling(bypassing) this, may still suffice

Error code : while running catkin_make -j1 from "catkin_ws" folder

[ 66%] Linking CXX executable /home/catkin_ws/devel/lib/rtabmap_demos/wifi_signal_sub
/usr/bin/ld: warning: libpcl_io.so.1.14, needed by /usr/local/lib/librtabmap_core.so.0.21.8, may conflict with libpcl_io.so.1.10
/usr/bin/ld: CMakeFiles/rtabmap_wifi_signal_sub.dir/src/WifiSignalSubNode.cpp.o: in function `mapDataCallback(boost::shared_ptr<rtabmap_msgs::MapData_<std::allocator<void> > const> const&)':
WifiSignalSubNode.cpp:(.text+0x15e2): undefined reference to `rtabmap::util3d::transformPointCloud(boost::shared_ptr<pcl::PointCloud<pcl::PointXYZRGB> > const&, rtabmap::Transform const&)'
collect2: error: ld returned 1 exit status
make[2]: *** [rtabmap_ros/rtabmap_demos/CMakeFiles/rtabmap_wifi_signal_sub.dir/build.make:545: /home/catkin_ws/devel/lib/rtabmap_demos/wifi_signal_sub] Error 1
make[1]: *** [CMakeFiles/Makefile2:6886: rtabmap_ros/rtabmap_demos/CMakeFiles/rtabmap_wifi_signal_sub.dir/all] Error 2
make: *** [Makefile:146: all] Error 2
Invoking "make -j1" failed

Dockerfile code

FROM nvidia/cuda:12.2.0-base-ubuntu20.04
ENV DEBIAN_FRONTEND=noninteractive

ARG depfolder=/home/

WORKDIR ${depfolder}

RUN apt update -y; \
    apt install -y build-essential wget  curl python3 python3-dev libxml2 nano git \ 
                    python3 python3-pip python3-dev python3-setuptools gfortran; 

#################
##### Install CMake  22
#################
RUN apt install -y libxrandr-dev libxinerama-dev libxi-dev libssl-dev; apt remove --purge cmake; hash -r;
RUN git clone https://github.com/Kitware/CMake.git; cd CMake; ./bootstrap && make -j60 && make install; cd ..

#cuSPARSELt
RUN apt install -y libcusparselt0 libcusparselt-dev

RUN wget -q https://developer.download.nvidia.com/compute/cuda/12.2.0/local_installers/cuda_12.2.0_535.54.03_linux.run
RUN sh cuda_12.2.0_535.54.03_linux.run --toolkit --silent
ENV LD_LIBRARY_PATH=/usr/local/cuda/lib64${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}
ENV PATH=/usr/local/cuda/bin${PATH:+:${PATH}}
RUN ldconfig 

# check the appropriate package based on ubuntu version (20 vs 22)
RUN wget https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2004/x86_64/cuda-keyring_1.1-1_all.deb -q
RUN echo "deb [signed-by=/usr/share/keyrings/cuda-archive-keyring.gpg] https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2004/x86_64/ /" > /etc/apt/sources.list.d/cuda.list
RUN dpkg -i cuda-keyring_1.1-1_all.deb
RUN apt-get update -q
RUN apt-get -y install cudnn-cuda-12

# #direct FWWT to cuWWT if compatible
ENV LD_PRELOAD=/usr/local/cuda/lib64/libcufft.so

# ################
# ## LAPACK install
# ################
RUN git clone https://github.com/Reference-LAPACK/lapack.git; \
    cd lapack; \
    mkdir build; \
    cd build; \
    cmake .. -DUSE_OPTIMIZED_LAPACK=ON; \
    cmake --build . -j60 --target install

# ################
# ## Eigen install
# ################

RUN apt install -y software-properties-common; apt-get update -y; \
        apt install -y libblas-dev liblz4-dev pkg-config liblz4-dev; \
        \
        add-apt-repository -y ppa:ubuntu-toolchain-r/test

RUN wget -qO- https://gitlab.com/libeigen/eigen/-/archive/3.3.7/eigen-3.3.7.tar.gz | tar xz; \
    cd eigen-3.3.7; mkdir build; cd build; \
    cmake .. -D  EIGEN_TEST_CUDA=ON; make -j58; make install; cd ../..

# ################
# ## FLANN install 
# ################

RUN git clone https://github.com/flann-lib/flann.git; cd flann; git pull origin  master; \
    mkdir build; cd build; \
    cmake .. -DCMAKE_BUILD_TYPE=Release -DBUILD_CUDA_LIB=ON ; make -j58; make install; cd ../..

RUN apt install libmpfr-dev libgmp-dev -y
RUN apt update; apt install -y  gcc-11 g++-11 
RUN apt -y update; update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-11 100; apt -y update
RUN update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-11 100

# ################
# ## SuiteSparse install  # cuda flags on , by default on cmake 
# ################
# RUN apt-get install gfortran-7
RUN git clone https://github.com/DrTimothyAldenDavis/SuiteSparse.git; cd SuiteSparse; git checkout stable; git pull origin  stable; \
    mkdir build; cd build; 
RUN apt install -y libopenblas-dev 
RUN cmake .. -DCMAKE_BUILD_TYPE=Release; make -j4; make install; cd ../..

# ###############
# # Boost Install 
# ###############

RUN wget https://boostorg.jfrog.io/artifactory/main/release/1.71.0/source/boost_1_71_0.tar.bz2; tar -xjf boost_1_71_0.tar.bz2
RUN apt-get install build-essential \
    g++ \
    gcc \
    python3-dev \
    python3-pip \
    libicu-dev \
    libbz2-dev \
    libssl-dev \
    libboost-all-dev \
    wget -y
RUN cd boost_1_71_0; ./bootstrap.sh --with-libraries=all
ENV PATH=/usr/local/cuda/bin:$PATH
ENV CUDADIR=/usr/local/cuda
RUN cd boost_1_71_0; ./b2; \ 
./b2 install --prefix=/usr/local/boost toolset=gcc cxxflags="-D__CUDACC__" --cuda=nvcc; cd ..
# RUN ./b2 install --prefix=/usr/local/boost
ENV BOOST_ROOT=/usr/local/boost
ENV CPLUS_INCLUDE_PATH="\${BOOST_ROOT}/include:\$CPLUS_INCLUDE_PATH"
ENV LIBRARY_PATH="\${BOOST_ROOT}/lib:\$LIBRARY_PATH"

# # ###############
# # ## VTK install
# # ###############

RUN git clone --recursive https://gitlab.kitware.com/vtk/vtk.git vtk/source; cd vtk/source; git checkout master git pull origin master; \
    cd ..; mkdir build
RUN cd vtk/build; \
 cmake ../source -DCMAKE_BUILD_TYPE=Release -DVTK_USE_CUDA=ON -DVTK_GROUP_ENABLE_Qt=NO -DVTK_MODULE_ENABLE_VTK_GUISupportQtQuick=NO -DVTK_MODULE_ENABLE_VTK_GUISupportQtSQL=NO -DVTK_MODULE_ENABLE_VTK_RenderingOpenVR=NO -DVTK_MODULE_ENABLE_VTK_RenderingRayTracing=NO -DVTK_MODULE_ENABLE_VTK_RenderingVR=NO -D CMAKE_VERBOSE_MAKEFILE=ON; \
 make -j20; make install
# for vtk 7.1
# RUN apt update -y; apt install libvtk7-dev -y

#############
## OPENCV for CUDA
############

RUN apt install cmake gcc g++ python3 python3-dev python3-numpy libavcodec-dev libavformat-dev libswscale-dev -y
RUN apt install -y libgstreamer-plugins-base1.0-dev libgstreamer1.0-dev libgtk-3-dev libpng-dev libjpeg-dev libopenexr-dev libtiff-dev libwebp-dev
RUN git clone https://github.com/opencv/opencv.git;\
    git clone https://github.com/opencv/opencv_contrib.git
RUN cd opencv; mkdir build; cd build; \ 
    cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D WITH_CUDA=ON -D WITH_CUDNN=ON -D WITH_CUBLAS=ON -DCUDA_SDK_ROOT_DIR=/usr/local/cuda -D OPENCV_DNN_CUDA=ON -D CUDA_ARCH_BIN=8.6 -D OPENCV_EXTRA_MODULES_PATH=../../opencv_contrib/modules -D HAVE_opencv_python3=ON -DCMAKE_CUDA_ARCHITECTURES="86" -DCUDA_FAST_MATH=ON -DLAPACK_INCLUDE_DIR=/home/lapack/build/include -DLAPACK_LIBRARIES=/home/lapack/build/lib ..
RUN cd opencv/build; make -j50; make install; ldconfig
# #use appropriate python version  
RUN ln -s /usr/local/lib/python3.8/site-packages/cv2 /usr/local/lib/python3.8/dist-packages/cv2 

# #############
# # PCL install
# #############

RUN apt-get update; apt-get install libboost-all-dev libcjson-dev libpcap-dev freeglut3 freeglut3-dev libpcap-dev qt5-qmake qtbase5-dev qtchooser \
 libusb-1.0-0-dev libopenni2-dev -y 

RUN git clone https://github.com/PointCloudLibrary/pcl.git && cd pcl && git checkout pcl-1.14.1; git pull origin pcl-1.14.1
RUN cd pcl; mkdir build; cd build; \

    cmake .. -D BUILD_CUDA=ON -D BUILD_GPU=ON -D WITH_OPENGL=OFF -DBUILD_cuda_io=ON -DBUILD_gpu_surface=ON -DBUILD_gpu_tracking=ON -DWITH_QT=OFF -DCUDA_SDK_ROOT_DIR=/usr/local/cuda -DCUDA_ARCH_BIN="86"
RUN cd pcl/build; make -j58; make install

##################
# CudaSift install
##################

RUN git clone https://github.com/matlabbe/CudaSift.git 
RUN cd CudaSift; mkdir build; cd build; \
    cmake .. -DCUDA_SDK_ROOT_DIR=/usr/local/cuda; \
    make; \ 
    make install

##################
# RTABMap install
###################
# has noetic-devel
RUN git clone https://github.com/introlab/rtabmap.git; git checkout 0.21.5-noetic; git pull origin 0.21.5-noetic; \
    cd rtabmap/build; cmake .. -D WITH_CUDASIFT=ON -D WITH_QT=OFF -DCUDA_SDK_ROOT_DIR=/usr/local/cuda -D CUDA_CUDA_LIBRARY=/usr/lib/x86_64-linux-gnu/libcuda.so
RUN cd rtabmap/build; make -j58; \
    make install

#####################
# ROS1 Noetic Install
#####################
RUN sh -c 'echo "deb http://packages.ros.org/ros/ubuntu $(lsb_release -sc) main" > /etc/apt/sources.list.d/ros-latest.list'
RUN apt-key adv --keyserver 'hkp://keyserver.ubuntu.com:80' --recv-key C1CF6E31E6BADE8868B172B4F42ED6FBAB17C654
RUN apt install -y python3-pip python3-setuptools python3-wheel
RUN apt update -y
RUN apt upgrade -y

RUN sh -c 'echo "deb http://packages.ros.org/ros/ubuntu $(lsb_release -sc) main" > /etc/apt/sources.list.d/ros-latest.list'
RUN curl -s https://raw.githubusercontent.com/ros/rosdistro/master/ros.asc | apt-key add -
RUN apt update -y
RUN apt install ros-noetic-ros-base -y
#[inside the container-after build] 
#source /opt/ros/noetic/setup.bash
#cd catkin_ws
#catkin_make -j60;
#source devel/setup.bash

#####################
# ROS1 Rtabmap-ros 
#####################
RUN mkdir catkin_ws; cd catkin_ws; mkdir src
RUN apt install -y ros-noetic-rtabmap* ros-noetic-libg2o ros-noetic-libpointmatcher
RUN apt remove ros-noetic-rtabmap* -y; 

RUN cd catkin_ws; git clone https://github.com/introlab/rtabmap_ros.git src/rtabmap_ros; cd src/rtabmap_ros; git checkout 0.21.5-noetic; git pull origin 0.21.5-noetic
RUN cd catkin_ws/src; git clone https://github.com/ros-perception/vision_opencv.git; git checkout noetic; git pull origin noetic
#[inside the container-after build] 
#cd catkin_ws
#catkin_make -j60

Tried to clean any irrelevant code I hope you can copy-paste without typos from my part

matlabbe commented 2 days ago

Maybe it is related to this warning:

/usr/bin/ld: warning: libpcl_io.so.1.14, needed by /usr/local/lib/librtabmap_core.so.0.21.8, may conflict with libpcl_io.so.1.10

As you are rebuilding everything from source, uninstall libpcl and ros-$ROS_DISTRO-pcl before rebuilding rtabmap

RUN apt remove ros-$ROS_DISTRO-pcl* libpcl* -y; 

You may need to rebuild pcl_ros from source too in case rtabmap_ros fails to find it.

GiannisSp commented 2 days ago

Thank you for your response. If I try to remove libpcl* , it also removes the ros-$ROS_DISTRO-pcl-conversions and other vital packages. Haven't installed ros-$ROS_DISTRO-pcl and even if it gets installed silently I can see that the Makefiles target my source build installation

My workaround is to delete the older version libpcl_io.so.1.10 and create a link to libpcl_io.so.1.14 . It didn't solve the issue.

All source builds up to RTABmap find perfectly each previous builds. That also seem to be the case with RTABmap_ros

matlabbe commented 1 day ago

it also removes the ros-$ROS_DISTRO-pcl-conversions and other vital packages

Yes, so you have to rebuild them from source.

Haven't installed ros-$ROS_DISTRO-pcl and even if it gets installed silently I can see that the Makefiles target my source build installation

The problem is that even if rtabmap is building against the pcl version built from source, on runtime the wrong library version can be loaded and it will just seg fault. You may verify that with ldd tool.

From experience, I've found that avoiding having the same libraries with different version installed at the same time saves a lot of issues down the road. Unless you really need latest PCL version, I would stick to the binaries to make your life easier. Note also rebuilding latest PCL on machine using c++17 by default can cause some issues. See https://github.com/introlab/rtabmap/issues/1385#issuecomment-2496318298 to set the right compile flags to avoid issues with GTSAM and g2o libraries using also Eigen library.

EDIT: just re-read original post, PCL-CUDA is not used by RTAB-Map.