PointCloudLibrary / pcl

Point Cloud Library (PCL)
https://pointclouds.org/
Other
10.01k stars 4.62k forks source link

[compile error] problem with #include <pcl/registration/icp.h> gives error in Eigen files #5922

Closed adheeshc closed 10 months ago

adheeshc commented 10 months ago

Describe the error

Im having a problem with #include <pcl/registration/icp.h>, as soon as i include this in my code and try to build with CMake, it gives me an error with a lot of the eigen3 files, specifically NonLinearOptimization files.
Including other things with pcl like visualizer, filters works fine

Eigen Version: 3.3.7 (also tested with Eigen 3.4.0 and 3.3.4) PCL Version: 1.10.0

/usr/local/include/eigen3/unsupported/Eigen/src/NonLinearOptimization/HybridNonLinearSolver.h:19:10: error: expected identifier before ‘int’
   19 |     enum Status {
      |          ^~~~~~
In file included from /usr/local/include/eigen3/unsupported/Eigen/NonLinearOptimization:136,
                 from /usr/include/pcl-1.10/pcl/sample_consensus/eigen.h:47,
                 from /usr/include/pcl-1.10/pcl/sample_consensus/sac_model_registration.h:45,
                 from /usr/include/pcl-1.10/pcl/registration/icp.h:46,
                 from /home/<user>/main.cpp:15:
/usr/local/include/eigen3/unsupported/Eigen/src/NonLinearOptimization/HybridNonLinearSolver.h:19:17: error: expected unqualified-id before ‘{’ token
   19 |     enum Status {
      |                 ^
In file included from /home/<user>/main.cpp:5:
/usr/local/include/eigen3/unsupported/Eigen/src/NonLinearOptimization/HybridNonLinearSolver.h:71:33: error: expected unqualified-id before ‘int’
   71 |     HybridNonLinearSolverSpace::Status hybrj1(
      |                                 ^~~~~~
/usr/local/include/eigen3/unsupported/Eigen/src/NonLinearOptimization/HybridNonLinearSolver.h:76:33: error: expected unqualified-id before ‘int’
   76 |     HybridNonLinearSolverSpace::Status solveInit(FVectorType  &x);
      |                                 ^~~~~~
/usr/local/include/eigen3/unsupported/Eigen/src/NonLinearOptimization/HybridNonLinearSolver.h:77:33: error: expected unqualified-id before ‘int’
   77 |     HybridNonLinearSolverSpace::Status solveOneStep(FVectorType  &x);
      |                                 ^~~~~~
/usr/local/include/eigen3/unsupported/Eigen/src/NonLinearOptimization/HybridNonLinearSolver.h:78:33: error: expected unqualified-id before ‘int’
   78 |     HybridNonLinearSolverSpace::Status solve(FVectorType  &x);
      |                                 ^~~~~~
/usr/local/include/eigen3/unsupported/Eigen/src/NonLinearOptimization/HybridNonLinearSolver.h:80:33: error: expected unqualified-id before ‘int’
   80 |     HybridNonLinearSolverSpace::Status hybrd1(
      |                                 ^~~~~~
/usr/local/include/eigen3/unsupported/Eigen/src/NonLinearOptimization/HybridNonLinearSolver.h:85:33: error: expected unqualified-id before ‘int’
   85 |     HybridNonLinearSolverSpace::Status solveNumericalDiffInit(FVectorType  &x);
      |                                 ^~~~~~
/usr/local/include/eigen3/unsupported/Eigen/src/NonLinearOptimization/HybridNonLinearSolver.h:86:33: error: expected unqualified-id before ‘int’
   86 |     HybridNonLinearSolverSpace::Status solveNumericalDiffOneStep(FVectorType  &x);
      |                                 ^~~~~~
/usr/local/include/eigen3/unsupported/Eigen/src/NonLinearOptimization/HybridNonLinearSolver.h:87:33: error: expected unqualified-id before ‘int’
   87 |     HybridNonLinearSolverSpace::Status solveNumericalDiff(FVectorType  &x);
      |                                 ^~~~~~
/usr/local/include/eigen3/unsupported/Eigen/src/NonLinearOptimization/HybridNonLinearSolver.h:121:29: error: expected unqualified-id before ‘int’
  121 | HybridNonLinearSolverSpace::Status
      |                             ^~~~~~
/usr/local/include/eigen3/unsupported/Eigen/src/NonLinearOptimization/HybridNonLinearSolver.h:142:29: error: expected unqualified-id before ‘int’
  142 | HybridNonLinearSolverSpace::Status
      |                             ^~~~~~
/usr/local/include/eigen3/unsupported/Eigen/src/NonLinearOptimization/HybridNonLinearSolver.h:185:29: error: expected unqualified-id before ‘int’
  185 | HybridNonLinearSolverSpace::Status
      |                             ^~~~~~
/usr/local/include/eigen3/unsupported/Eigen/src/NonLinearOptimization/HybridNonLinearSolver.h:343:29: error: expected unqualified-id before ‘int’
  343 | HybridNonLinearSolverSpace::Status
      |                             ^~~~~~
/usr/local/include/eigen3/unsupported/Eigen/src/NonLinearOptimization/HybridNonLinearSolver.h:357:29: error: expected unqualified-id before ‘int’
  357 | HybridNonLinearSolverSpace::Status
      |                             ^~~~~~
/usr/local/include/eigen3/unsupported/Eigen/src/NonLinearOptimization/HybridNonLinearSolver.h:379:29: error: expected unqualified-id before ‘int’
  379 | HybridNonLinearSolverSpace::Status
      |                             ^~~~~~
/usr/local/include/eigen3/unsupported/Eigen/src/NonLinearOptimization/HybridNonLinearSolver.h:425:29: error: expected unqualified-id before ‘int’
  425 | HybridNonLinearSolverSpace::Status
      |                             ^~~~~~
/usr/local/include/eigen3/unsupported/Eigen/src/NonLinearOptimization/HybridNonLinearSolver.h:586:29: error: expected unqualified-id before ‘int’
  586 | HybridNonLinearSolverSpace::Status
      |                             ^~~~~~
/usr/local/include/eigen3/unsupported/Eigen/src/NonLinearOptimization/LevenbergMarquardt.h:19:10: error: expected identifier before ‘int’
   19 |     enum Status {
      |          ^~~~~~
In file included from /usr/local/include/eigen3/unsupported/Eigen/NonLinearOptimization:137,
                 from /usr/include/pcl-1.10/pcl/sample_consensus/eigen.h:47,
                 from /usr/include/pcl-1.10/pcl/sample_consensus/sac_model_registration.h:45,
                 from /usr/include/pcl-1.10/pcl/registration/icp.h:46,
                 from /home/<user>/main.cpp:15:
/usr/local/include/eigen3/unsupported/Eigen/src/NonLinearOptimization/LevenbergMarquardt.h:19:17: error: expected unqualified-id before ‘{’ token
   19 |     enum Status {
      |                 ^
In file included from /home/<user>/src/main.cpp:5:
/usr/local/include/eigen3/unsupported/Eigen/src/NonLinearOptimization/LevenbergMarquardt.h:79:30: error: expected unqualified-id before ‘int’
   79 |     LevenbergMarquardtSpace::Status lmder1(
      |                              ^~~~~~
/usr/local/include/eigen3/unsupported/Eigen/src/NonLinearOptimization/LevenbergMarquardt.h:84:30: error: expected unqualified-id before ‘int’
   84 |     LevenbergMarquardtSpace::Status minimize(FVectorType &x);
      |                              ^~~~~~
/usr/local/include/eigen3/unsupported/Eigen/src/NonLinearOptimization/LevenbergMarquardt.h:85:30: error: expected unqualified-id before ‘int’
   85 |     LevenbergMarquardtSpace::Status minimizeInit(FVectorType &x);
      |                              ^~~~~~
/usr/local/include/eigen3/unsupported/Eigen/src/NonLinearOptimization/LevenbergMarquardt.h:86:30: error: expected unqualified-id before ‘int’
   86 |     LevenbergMarquardtSpace::Status minimizeOneStep(FVectorType &x);
      |                              ^~~~~~
/usr/local/include/eigen3/unsupported/Eigen/src/NonLinearOptimization/LevenbergMarquardt.h:88:37: error: expected unqualified-id before ‘int’
   88 |     static LevenbergMarquardtSpace::Status lmdif1(
      |                                     ^~~~~~
/usr/local/include/eigen3/unsupported/Eigen/src/NonLinearOptimization/LevenbergMarquardt.h:95:30: error: expected unqualified-id before ‘int’
   95 |     LevenbergMarquardtSpace::Status lmstr1(
      |                              ^~~~~~
/usr/local/include/eigen3/unsupported/Eigen/src/NonLinearOptimization/LevenbergMarquardt.h:100:30: error: expected unqualified-id before ‘int’
  100 |     LevenbergMarquardtSpace::Status minimizeOptimumStorage(FVectorType  &x);
      |                              ^~~~~~
/usr/local/include/eigen3/unsupported/Eigen/src/NonLinearOptimization/LevenbergMarquardt.h:101:30: error: expected unqualified-id before ‘int’
  101 |     LevenbergMarquardtSpace::Status minimizeOptimumStorageInit(FVectorType  &x);
      |                              ^~~~~~
/usr/local/include/eigen3/unsupported/Eigen/src/NonLinearOptimization/LevenbergMarquardt.h:102:30: error: expected unqualified-id before ‘int’
  102 |     LevenbergMarquardtSpace::Status minimizeOptimumStorageOneStep(FVectorType  &x);
      |                              ^~~~~~
/usr/local/include/eigen3/unsupported/Eigen/src/NonLinearOptimization/LevenbergMarquardt.h:134:26: error: expected unqualified-id before ‘int’
  134 | LevenbergMarquardtSpace::Status
      |                          ^~~~~~
/usr/local/include/eigen3/unsupported/Eigen/src/NonLinearOptimization/LevenbergMarquardt.h:157:26: error: expected unqualified-id before ‘int’
  157 | LevenbergMarquardtSpace::Status
      |                          ^~~~~~
/usr/local/include/eigen3/unsupported/Eigen/src/NonLinearOptimization/LevenbergMarquardt.h:170:26: error: expected unqualified-id before ‘int’
  170 | LevenbergMarquardtSpace::Status
      |                          ^~~~~~
/usr/local/include/eigen3/unsupported/Eigen/src/NonLinearOptimization/LevenbergMarquardt.h:213:26: error: expected unqualified-id before ‘int’
  213 | LevenbergMarquardtSpace::Status
      |                          ^~~~~~
/usr/local/include/eigen3/unsupported/Eigen/src/NonLinearOptimization/LevenbergMarquardt.h:362:26: error: expected unqualified-id before ‘int’
  362 | LevenbergMarquardtSpace::Status
      |                          ^~~~~~
/usr/local/include/eigen3/unsupported/Eigen/src/NonLinearOptimization/LevenbergMarquardt.h:384:26: error: expected unqualified-id before ‘int’
  384 | LevenbergMarquardtSpace::Status
      |                          ^~~~~~
/usr/local/include/eigen3/unsupported/Eigen/src/NonLinearOptimization/LevenbergMarquardt.h:433:26: error: expected unqualified-id before ‘int’
  433 | LevenbergMarquardtSpace::Status
      |                          ^~~~~~
/usr/local/include/eigen3/unsupported/Eigen/src/NonLinearOptimization/LevenbergMarquardt.h:612:26: error: expected unqualified-id before ‘int’
  612 | LevenbergMarquardtSpace::Status
      |                          ^~~~~~
/usr/local/include/eigen3/unsupported/Eigen/src/NonLinearOptimization/LevenbergMarquardt.h:625:26: error: expected unqualified-id before ‘int’
  625 | LevenbergMarquardtSpace::Status
      |                          ^~~~~~
make[2]: *** [CMakeFiles/pclIL.dir/build.make:63: CMakeFiles/pclIL.dir/src/main.cpp.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:76: CMakeFiles/pclIL.dir/all] Error 2
make: *** [Makefile:84: all] Error 2

Your Environment (please complete the following information):

Found flann, version 1.9.1 Eigen found (include: /usr/include/eigen3, version: 3.3.7) Found Boost: /usr/include (found suitable version "1.71.0", minimum required is "1.55.0") found components: system filesystem date_time iostreams regex

looking for PCL_REGISTRATION -- Found PCL_REGISTRATION: /usr/lib/x86_64-linux-gnu/libpcl_registration.so

mvieth commented 10 months ago

Is it possible that you define Status as a preprocessor symbol, or that some other file you include does this? I found: https://github.com/opencv/opencv/issues/7113 which seems to be a similar problem. You could try to include icp.h as the very first thing, then everything else. Alternatively you could use a newer PCL version. In PCL 1.11.1 and newer, icp.h no longer includes sac_model_registration.h, which should break this include chain.

adheeshc commented 10 months ago

So I followed the opencv issue you tagged. Seems that #include <X11/Xlib.h> causes the issue.

As someone suggested in the opencv issue you posted, the workaround for this problem is possible by including PCL headers before Xlib.h in application code

Tested it out and seems to work fine as a workaround,

Better to add a macro check with problem like [here] (https://github.com/opencv/opencv/pull/6161/commits/3cc234588abc3064cf0d5d3113d9bbb75b6a54cf).