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.58k stars 759 forks source link

Eigen compilation issue #940

Closed ghost closed 2 years ago

ghost commented 2 years ago

Description

When compiling on Ubuntu 21.10 after installing dependencies through apt, the project fails to compile (I have attached the output of make check here: gtsamMakeCheckLog.txt)

Steps to reproduce

  1. Install dependencies via apt on Ubuntu 21.10
  2. Attempt to build

Expected behavior

The library is expected to compile

Environment

I am using Ubuntu 21.10, gcc 11.2.0, cmake 3.18.4, boost 1.74, and the develop branch

Additional information

This issue has already been mentioned in this pull request, but the patch mentioned is no longer available https://github.com/borglab/gtsam/pull/391#issuecomment-663814121

jlblancoc commented 2 years ago

Could you show the full command line of the failing file? i.e. the last big fat line when doing VERBOSE=1 make -j1

ghost commented 2 years ago
cd /home/quincy/Documents/LinuxVR/gtsam/build/gtsam && /usr/bin/c++ -DBOOST_ALL_NO_LIB -DBOOST_ATOMIC_DYN_LINK -DBOOST_CHRONO_DYN_LINK -DBOOST_DATE_TIME_DYN_LINK -DBOOST_FILESYSTEM_DYN_LINK -DBOOST_REGEX_DYN_LINK -DBOOST_SERIALIZATION_DYN_LINK -DBOOST_SYSTEM_DYN_LINK -DBOOST_THREAD_DYN_LINK -DBOOST_TIMER_DYN_LINK -DNDEBUG -Dgtsam_EXPORTS -I/home/quincy/Documents/LinuxVR/gtsam -I/home/quincy/Documents/LinuxVR/gtsam/build -I/home/quincy/Documents/LinuxVR/gtsam/CppUnitLite -I/home/quincy/Documents/LinuxVR/gtsam/gtsam/3rdparty/Eigen -I/home/quincy/Documents/LinuxVR/gtsam/gtsam/3rdparty/metis/include -I/home/quincy/Documents/LinuxVR/gtsam/gtsam/3rdparty/metis/libmetis -I/home/quincy/Documents/LinuxVR/gtsam/gtsam/3rdparty/metis/GKlib -isystem /home/quincy/Documents/LinuxVR/gtsam/gtsam/3rdparty/SuiteSparse_config -isystem /home/quincy/Documents/LinuxVR/gtsam/gtsam/3rdparty/Spectra -isystem /home/quincy/Documents/LinuxVR/gtsam/gtsam/3rdparty/CCOLAMD/Include -O3 -DNDEBUG -fPIC -march=native -Wall -fPIC -Wreturn-local-addr -Werror=return-local-addr -Wreturn-type -Werror=return-type -Wformat -Werror=format-security -Wsuggest-override -O3 -Wno-unused-local-typedefs -o CMakeFiles/gtsam.dir/navigation/CombinedImuFactor.cpp.o -c /home/quincy/Documents/LinuxVR/gtsam/gtsam/navigation/CombinedImuFactor.cpp
ghost commented 2 years ago

The comment on the pull request I mentioned earlier (this: https://github.com/borglab/gtsam/pull/391#issuecomment-663814121) said that this issue was only with c++17, so I ran the compile command I commented earlier with an added -std=c++11 to compile only that file in c++11, and because make checks for object files before attempting to compile, I managed to get the library to build.

jlblancoc commented 2 years ago

Ah! It must be a new issue with g++11.2 Perhaps g++11 should be added to the CI build matrix?

From here:

GCC 11 Now Defaults To C++17 Dialect By Default

So this is gonna become a real issue for most users if they get the latest g++ but not the latest Eigen3... An ugly workaround might be a special build flag for the affected file(s) (via cmake source file properties), or wait for the move to c++17.

varunagrawal commented 2 years ago

Oh I encountered this exact issue and have proposed a fix to it here #944 This is indeed an issue with GCC 8+.

ProfFan commented 2 years ago

There is a catch here: most people will use system Eigen which is not 3.3.9. I would suggest we do some kind of work-around in our code instead.

varunagrawal commented 2 years ago

The workaround isn't something we can do trivially. We can use CMake to force 3.3.9 and this shouldn't be a major issue since it is a patch version update.

ProfFan commented 2 years ago

@varunagrawal it is easy to do: https://github.com/humanoid-path-planner/hpp-fcl/pull/226/files

varunagrawal commented 2 years ago

Cool! I still think we should update eigen since there are other big fixes that we can benefit from.

Asking users to update eigen is a small task for the rewards.

dellaert commented 2 years ago

@varunagrawal upgrading system eigen is not trivial so I vote to work-around in our code. Please update PR #944 with other reasons to upgrade. Please do not merge until serialization is validated with old Eigen version.

varunagrawal commented 2 years ago

Okay, I am updating #944 with the workaround that Fan linked.

varunagrawal commented 2 years ago

Huh @ProfFan that fix doesn't work. I am getting the error

In file included from /usr/local/include/gtsam/base/serializationTestHelpers.h:26,
                 from /home/varun/borglab/GTDynamics/tests/testHelicalJoint.cpp:17:
/usr/local/include/gtsam/base/serialization.h:49:19: error: ‘traits’ is not a class template
   49 | template<> struct traits<boost::serialization::U> {enum {Flags=0};};
      |                   ^~~~~~
/usr/local/include/gtsam/base/serialization.h:49:51: error: explicit specialization of non-template ‘Eigen::internal::traits’
   49 | template<> struct traits<boost::serialization::U> {enum {Flags=0};};
      |                                                   ^
varunagrawal commented 2 years ago

Also, maintainers of Eigen also call it an "ugly hack" https://gitlab.com/libeigen/eigen/-/issues/1676#note_709679901

varunagrawal commented 2 years ago

Let me take a closer look at this.

varunagrawal commented 2 years ago

Figured it out. We need to include Eigen/Core as well. This was mentioned in the original SO answer and not in the PR.