borglab / gtsam

GTSAM is a library of C++ classes that implement smoothing and mapping (SAM) in robotics and vision, using factor graphs and Bayes networks as the underlying computing paradigm rather than sparse matrices.
http://gtsam.org
Other
2.6k stars 764 forks source link

tbb/scalable_allocator.h: No such file or directory (RHEL) #1769

Closed matlabbe closed 3 months ago

matlabbe commented 4 months ago

Description

When building our code with ros-jazzy-gtsam binaries on RHEL, it seems the include directory for TBB used by gtsam is not propagated downstream (well, it is missing), causing that error:

06:38:20 DEBUG: [ 31%] Building CXX object corelib/src/CMakeFiles/rtabmap_core.dir/optimizer/OptimizerGTSAM.cpp.o
06:38:20 DEBUG: cd /builddir/build/BUILD/ros-jazzy-rtabmap-0.21.5/.obj-x86_64-redhat-linux-gnu/corelib/src && /usr/bin/g++ -DDISABLE_LIBUSB -DDISABLE_PCAP -DDISABLE_PNG -DPCL_OMP -DQT_CORE_LIB -DQT_GUI_LIB -DQT_NO_DEBUG -DQT_NO_KEYWORDS -DQT_OPENGL_LIB -DQT_WIDGETS_LIB -DVTK_GLOBAL_WARNING_DISPLAY_OFF -Dkiss_fft_scalar=double -Dqh_QHpointer -Drtabmap_core_EXPORTS -I/builddir/build/BUILD/ros-jazzy-rtabmap-0.21.5/corelib/src -I/builddir/build/BUILD/ros-jazzy-rtabmap-0.21.5/corelib/src/../include -I/builddir/build/BUILD/ros-jazzy-rtabmap-0.21.5/.obj-x86_64-redhat-linux-gnu/corelib/src -I/builddir/build/BUILD/ros-jazzy-rtabmap-0.21.5/.obj-x86_64-redhat-linux-gnu/corelib/src/include -I/opt/ros/jazzy/lib/cmake/GTSAM/../../../include -I/builddir/build/BUILD/ros-jazzy-rtabmap-0.21.5/utilite/src/../include -I/builddir/build/BUILD/ros-jazzy-rtabmap-0.21.5/.obj-x86_64-redhat-linux-gnu/utilite/src/include -isystem /opt/ros/jazzy/include -isystem /usr/include/eigen3 -isystem /usr/include/opencv4 -isystem /usr/include/pcl-1.12 -isystem /usr/include/ni -isystem /usr/include/vtk -isystem /usr/include/freetype2 -isystem /usr/include/qt5 -isystem /usr/include/qt5/QtWidgets -isystem /usr/include/qt5/QtGui -isystem /usr/include/qt5/QtCore -isystem /usr/lib64/qt5/mkspecs/linux-g++ -isystem /usr/include/qt5/QtOpenGL -isystem /opt/ros/jazzy/include/g2o/core -isystem /opt/ros/jazzy/include/g2o/stuff -isystem /opt/ros/jazzy/include/g2o/solvers/eigen -isystem /opt/ros/jazzy/include/g2o/solvers/pcg -isystem /opt/ros/jazzy/include/g2o/types/slam2d -isystem /opt/ros/jazzy/include/g2o/types/slam3d -isystem /opt/ros/jazzy/include/g2o/types/sba -isystem /opt/ros/jazzy/include/g2o/solvers/csparse -isystem /usr/include/suitesparse -isystem /opt/ros/jazzy/include/g2o/solvers/cholmod -isystem /opt/ros/jazzy/include/gtsam/3rdparty/SuiteSparse_config -isystem /opt/ros/jazzy/include/gtsam/3rdparty/CCOLAMD -isystem /opt/ros/jazzy/include/gtsam/3rdparty/metis -isystem /opt/ros/jazzy/include/gtsam/3rdparty/Eigen -O2 -flto=auto -ffat-lto-objects -fexceptions -g -grecord-gcc-switches -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -fstack-protector-strong -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1  -m64 -march=x86-64-v2 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -fmessage-length=0 -fopenmp -std=c++17 -DNDEBUG -std=gnu++17 -fPIC   -Wall -Wno-unknown-pragmas -fPIC -fopenmp -MD -MT corelib/src/CMakeFiles/rtabmap_core.dir/optimizer/OptimizerGTSAM.cpp.o -MF CMakeFiles/rtabmap_core.dir/optimizer/OptimizerGTSAM.cpp.o.d -o CMakeFiles/rtabmap_core.dir/optimizer/OptimizerGTSAM.cpp.o -c /builddir/build/BUILD/ros-jazzy-rtabmap-0.21.5/corelib/src/optimizer/OptimizerGTSAM.cpp
06:38:23 DEBUG: In file included from /opt/ros/jazzy/include/gtsam/global_includes.h:22,
06:38:23 DEBUG:                  from /opt/ros/jazzy/include/gtsam/base/Vector.h:28,
06:38:23 DEBUG:                  from /opt/ros/jazzy/include/gtsam/base/Matrix.h:28,
06:38:23 DEBUG:                  from /opt/ros/jazzy/include/gtsam/base/Manifold.h:22,
06:38:23 DEBUG:                  from /opt/ros/jazzy/include/gtsam/geometry/BearingRange.h:21,
06:38:23 DEBUG:                  from /opt/ros/jazzy/include/gtsam/geometry/Pose2.h:23,
06:38:23 DEBUG:                  from /builddir/build/BUILD/ros-jazzy-rtabmap-0.21.5/corelib/src/optimizer/OptimizerGTSAM.cpp:39:
06:38:23 DEBUG: /opt/ros/jazzy/include/gtsam/base/types.h:34:10: fatal error: tbb/scalable_allocator.h: No such file or directory
06:38:23 DEBUG:    34 | #include <tbb/scalable_allocator.h>
06:38:23 DEBUG:       |          ^~~~~~~~~~~~~~~~~~~~~~~~~~
06:38:23 DEBUG: compilation terminated.
06:38:23 DEBUG: make[2]: *** [corelib/src/CMakeFiles/rtabmap_core.dir/build.make:947: corelib/src/CMakeFiles/rtabmap_core.dir/optimizer/OptimizerGTSAM.cpp.o] Error 1

Full log here: https://build.ros2.org/job/Jbin_rhel_el964__rtabmap__rhel_9_x86_64__binary/35/consoleFull

We don't see that error on Ubuntu Noble, only on RHEL.

Steps to reproduce

We include gtsam this way:

find_package(GTSAM CONFIG QUIET)
include_directories(${GTSAM_INCLUDE_DIRS})
add_executable(my_app main.cpp)
target_link_libraries(my_app PRIVATE gtsam)

Minimal code example that would reproduce the issue:

#include <gtsam/base/types.h>
int main(int argc, char * argv[])
{
    return 0;
}

Note however I don't know exactly the machine configuration used by the ros2 buildfarm for RHEL.

Expected behavior

Not having build error.

Environment

ROS2 Jazzy on RHEL. The error doesn't happen with ROS2 Jazzy on Ubuntu Noble.

Additional information

See https://github.com/introlab/rtabmap/issues/1306 for original issue.

ProfFan commented 4 months ago

The way we handled CMake dependencies may need to be revamped (which is a big project!). If we stop supporting old releases of TBB and other dependencies (as 18.04 is EOL) we might be able to let CMake handle all these itself...

For now I think I need a bit more information, but I guess it's a hard coded path somewhere...

matlabbe commented 4 months ago

I reproduced the issue with this Dockerfile:

FROM almalinux:latest

RUN dnf install langpacks-en glibc-langpack-en -y

ENV LANG=en_US.UTF-8

RUN dnf install 'dnf-command(config-manager)' epel-release -y && \
  dnf config-manager --set-enabled crb

RUN curl --output /etc/yum.repos.d/ros2.repo http://packages.ros.org/ros2/rhel/ros2.repo && \
  dnf makecache -y

RUN dnf install -y \
  cmake \
  gcc-c++ \
  git \
  make \
  python3-colcon-common-extensions \
  python3-mypy \
  python3-pip \
  python3-pydocstyle \
  python3-pytest \
  python3-pytest-repeat \
  python3-pytest-rerunfailures \
  python3-rosdep \
  python3-setuptools \
  python3-vcstool \
  wget \
  ros-jazzy-ros-base \
  ros-jazzy-gtsam \
  boost-devel

RUN source /opt/ros/jazzy/setup.bash && \
    echo -e "#include <gtsam/base/types.h>\nint main(int argc, char * argv[]) {return 0;}" > main.cpp && \
    echo -e "project(test)\nfind_package(GTSAM CONFIG REQUIRED)\nadd_executable(my_app main.cpp)\ntarget_link_libraries(my_app PRIVATE gtsam)" > CMakeLists.txt && \
  cmake . && \
  make VERBOSE=1

Output:

0.789 -- Build files have been written to: /
0.808 [ 50%] Building CXX object CMakeFiles/my_app.dir/main.o
0.967 In file included from /main.cpp:1:
0.967 /opt/ros/jazzy/include/gtsam/base/types.h:34:10: fatal error: tbb/scalable_allocator.h: No such file or directory
0.967    34 | #include <tbb/scalable_allocator.h>
0.967       |          ^~~~~~~~~~~~~~~~~~~~~~~~~~
0.967 compilation terminated.
0.969 make[2]: *** [CMakeFiles/my_app.dir/build.make:76: CMakeFiles/my_app.dir/main.o] Error 1
0.969 make[1]: *** [CMakeFiles/Makefile2:83: CMakeFiles/my_app.dir/all] Error 2
0.969 make: *** [Makefile:91: all] Error 2

To fix the issue, we need to install manually tbb-devel, add it to install command before making the script. Note that just by installing ros-jazzy-gtsam, the boost libraries were also missing. I am not sure if boost and tbb dependencies in package.xml is written correctly: https://github.com/borglab/gtsam/blob/a2a7a066464c4f147aad74bd98efccfe0f53baae/package.xml#L26-L28

Maybe the fix is just to change to the following so that boost and tbb are propagated downstream (not just for gtsam build):

 <depend>boost</depend> 
 <depend>eigen</depend> 
 <depend>tbb</depend>
ProfFan commented 3 months ago

Yes these should be depend not just build dependency.

ProfFan commented 3 months ago

@matlabbe Could you do a simple PR to main? Thank you!

matlabbe commented 3 months ago

Created! https://github.com/borglab/gtsam/pull/1772