Skip to content

Sophus and eigen version problem #187

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
JHzss opened this issue Dec 22, 2018 · 17 comments
Closed

Sophus and eigen version problem #187

JHzss opened this issue Dec 22, 2018 · 17 comments
Labels

Comments

@JHzss
Copy link

JHzss commented Dec 22, 2018

/usr/local/include/sophus/so2.hpp:98:40: error: ‘ScalarBinaryOpTraits’ in namespace ‘Eigen’ does not name a type
using ReturnScalar = typename Eigen::ScalarBinaryOpTraits<
^
/usr/local/include/sophus/so2.hpp:102:26: error: ‘ReturnScalar’ was not declared in this scope
using SO2Product = SO2<ReturnScalar>;
^
/usr/local/include/sophus/so2.hpp:102:39: error: template argument 1 is invalid
using SO2Product = SO2<ReturnScalar>;
^
/usr/local/include/sophus/so2.hpp:105:32: error: ‘ReturnScalar’ was not declared in this scope
using PointProduct = Vector2<ReturnScalar>;
^
/usr/local/include/sophus/so2.hpp:105:45: error: template argument 1 is invalid
using PointProduct = Vector2<ReturnScalar>;
^
/usr/local/include/sophus/so2.hpp:108:43: error: ‘ReturnScalar’ was not declared in this scope
using HomogeneousPointProduct = Vector3<ReturnScalar>;
^
/usr/local/include/sophus/so2.hpp:108:56: error: template argument 1 is invalid
using HomogeneousPointProduct = Vector3<ReturnScalar>;
^
/usr/local/include/sophus/so2.hpp:206:15: error: ‘SO2Product’ does not name a type
SOPHUS_FUNC SO2Product operator*(
^
/usr/local/include/sophus/so2.hpp:241:15: error: ‘PointProduct’ does not name a type
SOPHUS_FUNC PointProduct operator*(
^
/usr/local/include/sophus/so2.hpp:257:15: error: ‘HomogeneousPointProduct’ does not name a type
SOPHUS_FUNC HomogeneousPointProduct operator*(
^
/usr/local/include/sophus/so2.hpp:281:38: error: ‘ReturnScalar’ was not declared in this scope
std::is_same<Scalar, ReturnScalar>::value>::type>
^
/usr/local/include/sophus/so2.hpp:281:51: error: template argument 2 is invalid
std::is_same<Scalar, ReturnScalar>::value>::type>
^
/usr/local/include/sophus/so2.hpp:281:63: error: template argument 1 is invalid
std::is_same<Scalar, ReturnScalar>::value>::type>
^
/usr/local/include/sophus/so2.hpp:281:73: error: ‘type’ in namespace ‘::’ does not name a type
std::is_same<Scalar, ReturnScalar>::value>::type>

@JHzss
Copy link
Author

JHzss commented Dec 22, 2018

the eigen version is 3.3.5 , and the newest version of sophus

@yupinov
Copy link

yupinov commented Mar 20, 2019

Are you absolutely sure it wasn't picking up some older Eigen from a different path? In my case, it was 3.2.92 (3.3-beta1) from Ubuntu 16.04.

@ParikaGoel
Copy link

I am also trying to use the eigen, sophus and ceres libraries together.
I cloned latest stable releases of all the libraries, compiled and installed them from the source code

Eigen Library Version : 3.3.7
Sophus : 1.0.0
Ceres : 1.14.0

I am able to compile everything. But when I run my code, I get following error

/usr/local/include/eigen3/Eigen/src/Core/functors/AssignmentFunctors.h:24:102: error: cannot convert ‘const ceres::Jet<double, 7>’ to ‘double’ in assignment
gnCoeff(DstScalar& a, const SrcScalar& b) const { a = b; }

@JHzss
Copy link
Author

JHzss commented Jun 28, 2019

@ParikaGoel Maybe you used 'AutoDiffCostFunction', right?

@ParikaGoel
Copy link

ParikaGoel commented Jun 28, 2019

@ParikaGoel Maybe you used 'AutoDiffCostFunction', right?

Yes I am using 'AutoDiffCostFunction'.
Below is my operator function for the cost:

template
bool PointToPlaneConstraint::operator()(const T* const sPose, T* sResiduals) const {
// map inputs
Eigen::Map<Sophus::SE3 const> const pose(sPose);
Eigen::Vector3d transformed_point = pose * m_source_point; <<< Error at this line
Eigen::Vector3d diff_point = transformed_point - m_target_point;
sResiduals[0] = T(diff_point.dot(m_target_normal));
return true;
}

@JHzss
Copy link
Author

JHzss commented Jun 28, 2019

@ParikaGoel Maybe you can delete this part of the code temporarily to see if the error disappear. I'm not sure you have the same error as me. If you confirm that and know the type of data(double or float or others) exactly, you can have a try to replace the 'AutoDiffCostFunction' with 'CostFunctionToFunctor' . I didn't solved the version problem yet but I used the 'CostFunctionToFunctor' to solve it. I hope it will help you.

@NikolausDemmel
Copy link
Contributor

@ParikaGoel, your error has nothing to do with the eigen / sophus / ceres version. You need to use the template parameter T as Scalar type for intermediate values that depend on the input to use that with ceres' auto diff.

bool PointToPlaneConstraint::operator()(const T* const sPose, T* sResiduals) const {
// map inputs
Eigen::Map<Sophus::SE3 const> const pose(sPose);
Eigen::Matrix<T, 3, 1> transformed_point = pose * m_source_point;
Eigen::Matrix<T, 3, 1> diff_point = transformed_point - m_target_point;
sResiduals[0] = T(diff_point.dot(m_target_normal));
return true;
}

Looks like maybe for pose the compiler can deduce the template argument, else use Eigen::Map<Sophus::SE3<T> const> const pose(sPose);

@ParikaGoel
Copy link

@ParikaGoel, your error has nothing to do with the eigen / sophus / ceres version. You need to use the template parameter T as Scalar type for intermediate values that depend on the input to use that with ceres' auto diff.

bool PointToPlaneConstraint::operator()(const T* const sPose, T* sResiduals) const {
// map inputs
Eigen::Map<Sophus::SE3 const> const pose(sPose);
Eigen::Matrix<T, 3, 1> transformed_point = pose * m_source_point;
Eigen::Matrix<T, 3, 1> diff_point = transformed_point - m_target_point;
sResiduals[0] = T(diff_point.dot(m_target_normal));
return true;
}

Looks like maybe for pose the compiler can deduce the template argument, else use Eigen::Map<Sophus::SE3<T> const> const pose(sPose);

Thanks for the explanation...this worked for me :)
@JHzss Maybe you can try this approach as well

@epiception
Copy link

Found this error in another repo using sophus as a dependency, is there a solution for this?

@NikolausDemmel
Copy link
Contributor

To fix the error about missing ScalarBinaryOpTraits, you need to make sure the project is using Eigen version >= 3.3 and that the correct includes are actually picked up (and not e.g. some system-installed older Eigen).

@epiception
Copy link

Thanks!
The problem was with libeigen3-dev (needed by ROS Full Desktop install).
I resolved this by adding SET( EIGEN3_INCLUDE_DIR /path/to/latest_eigen3_folder) and installed it in usr/include/

@narutojxl
Copy link

Hi @NikolausDemmel, my system is ubuntu16.04, the system's eigen default is installed in /usr/include/eigen3, version is 3.2.92. When building Sophus master, i modified the CMakeLists.txt of Sophus as fllows:

# Add local path for finding packages, set the local version first
#list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake_modules")  
#jxl:  not use the source directory's  FindEigen3.cmake

# Find Eigen 3 (dependency)
#find_package(Eigen3 3.3.0 REQUIRED)


#jxl: want to use the locally installed eigen, not the system's old eigen 
list(APPEND CMAKE_PREFIX_PATH "/home/jxl/third_softwares/eigen_3_3_7/INSTALL_DIR/")
#set(CMAKE_PREFIX_PATH "/home/jxl/third_softwares/eigen_3_3_7/INSTALL_DIR/")
find_package(Eigen3 3.3.7 REQUIRED)

But the config file seems like not find the my locally installed eigen, still found the system's eigen. How to set to use the >3.3.0 version eigen, not the system's old eigen(3.2.92). Thanks for your help and time!

jxl@dell:~/third_softwares/Sophus-master/Sophus/build_dir$ cmake ..
-- The C compiler identification is GNU 5.4.0
-- The CXX compiler identification is GNU 5.4.0
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc - works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ - works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found installed version of Eigen: /usr/lib/cmake/eigen3
-- Found required Ceres dependency: Eigen version 3.2.92 in /usr/include/eigen3
-- Found required Ceres dependency: glog
-- Found installed version of gflags: /home/jxl/segmap_ws/build/gflags_catkin/gflags_src-prefix/src/gflags_src
-- Detected broken gflags install in: /home/jxl/segmap_ws/build/gflags_catkin/gflags_src-prefix/src/gflags_src, version: 2.1.2 <= 2.1.2 which defines gflags_LIBRARIES = gflags which is not an imported CMake target, see: https://github.com/gflags/gflags/issues/110.  Attempting to fix by detecting correct gflags target.
-- Found valid gflags target: gflags-shared, updating gflags_LIBRARIES.
-- Detected gflags version: 2.1.2
-- Found required Ceres dependency: gflags
-- Ceres version 1.14.0 detected here: /usr/local was built with C++11. Ceres target will add C++11 flags to compile options for targets using it.
-- Found Ceres version: 1.14.0 installed in: /usr/local with components: [EigenSparse, SparseLinearAlgebraLibrary, LAPACK, SuiteSparse, CXSparse, SchurSpecializations, C++11, OpenMP, Multithreading]
-- Found installed version of Eigen: /usr/lib/cmake/eigen3
-- Found required Ceres dependency: Eigen version 3.2.92 in /usr/include/eigen3
-- Found required Ceres dependency: glog
-- Found installed version of gflags: /home/jxl/segmap_ws/build/gflags_catkin/gflags_src-prefix/src/gflags_src
-- Detected broken gflags install in: /home/jxl/segmap_ws/build/gflags_catkin/gflags_src-prefix/src/gflags_src, version: 2.1.2 <= 2.1.2 which defines gflags_LIBRARIES = gflags which is not an imported CMake target, see: https://github.com/gflags/gflags/issues/110.  Attempting to fix by detecting correct gflags target.
-- Found valid gflags target: gflags-shared, updating gflags_LIBRARIES.
-- Detected gflags version: 2.1.2
-- Found required Ceres dependency: gflags
-- Ceres version 1.14.0 detected here: /usr/local was built with C++11. Ceres target will add C++11 flags to compile options for targets using it.
-- Found Ceres version: 1.14.0 installed in: /usr/local with components: [EigenSparse, SparseLinearAlgebraLibrary, LAPACK, SuiteSparse, CXSparse, SchurSpecializations, C++11, OpenMP, Multithreading]
-- CERES found
-- Found installed version of Eigen: /usr/lib/cmake/eigen3
-- Found required Ceres dependency: Eigen version 3.2.92 in /usr/include/eigen3
-- Found required Ceres dependency: glog
-- Found installed version of gflags: /home/jxl/segmap_ws/build/gflags_catkin/gflags_src-prefix/src/gflags_src
-- Detected broken gflags install in: /home/jxl/segmap_ws/build/gflags_catkin/gflags_src-prefix/src/gflags_src, version: 2.1.2 <= 2.1.2 which defines gflags_LIBRARIES = gflags which is not an imported CMake target, see: https://github.com/gflags/gflags/issues/110.  Attempting to fix by detecting correct gflags target.
-- Found valid gflags target: gflags-shared, updating gflags_LIBRARIES.
-- Detected gflags version: 2.1.2
-- Found required Ceres dependency: gflags
-- Ceres version 1.14.0 detected here: /usr/local was built with C++11. Ceres target will add C++11 flags to compile options for targets using it.
-- Found Ceres version: 1.14.0 installed in: /usr/local with components: [EigenSparse, SparseLinearAlgebraLibrary, LAPACK, SuiteSparse, CXSparse, SchurSpecializations, C++11, OpenMP, Multithreading]
-- Configuring done
-- Generating done
-- Build files have been written to: /home/jxl/third_softwares/Sophus-master/Sophus/build_dir
jxl@dell:~/third_softwares/Sophus-master/Sophus/build_dir$ 

@NikolausDemmel
Copy link
Contributor

Check the find module: https://github.com/strasdat/Sophus/blob/master/cmake_modules/FindEigen3.cmake

It's rather limited, but I think you can either explicitly set EIGEN3_INCLUDE_DIR when calling cmake, or set Eigen3_ROOT (see https://cmake.org/cmake/help/latest/command/find_path.html).

Or you change the main cmake file to call find_package with additional argument NO_MODULE (or remove this line:

list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake_modules")
), to force it to look for the install config files on the CMAKE_PREFIX_PATH, which should then first find your custom version if you set it accordingly:
find_package(Eigen3 3.3.0 REQUIRED)

@narutojxl
Copy link

Yes, @NikolausDemmel , thanks for your help!
I comment the list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake_modules") in Sophus/CMakeLists.txt:
2020-07-24 19-34-15屏幕截图
The output is:

jxl@dell:~/third_softwares/Sophus-master/Sophus/build_dir$ cmake ..
{====eigen path====} = /home/jxl/third_softwares/eigen_3_3_7/INSTALL_DIR/include/eigen3

{====eigen version====} = 3.3.7

It found my custom eigen 3.3.7, but it also found ceres, which is built with eigen 3.2.92 a long time before.

-- CERES found
-- Found installed version of Eigen: /usr/lib/cmake/eigen3
-- Found required Ceres dependency: Eigen version 3.2.92 in /usr/include/eigen3
-- Found required Ceres dependency: glog
-- Found installed version of gflags: /home/jxl/segmap_ws/build/gflags_catkin/gflags_src-prefix/src/gflags_src
-- Detected broken gflags install in: /home/jxl/segmap_ws/build/gflags_catkin/gflags_src-prefix/src/gflags_src, version: 2.1.2 <= 2.1.2 which defines gflags_LIBRARIES = gflags which is not an imported CMake target, see: https://github.com/gflags/gflags/issues/110.  Attempting to fix by detecting correct gflags target.
-- Found valid gflags target: gflags-shared, updating gflags_LIBRARIES.
-- Detected gflags version: 2.1.2
-- Found required Ceres dependency: gflags
-- Ceres version 1.14.0 detected here: /usr/local was built with C++11. Ceres target will add C++11 flags to compile options for targets using it.
-- Found Ceres version: 1.14.0 installed in: /usr/local with components: [EigenSparse, SparseLinearAlgebraLibrary, LAPACK, SuiteSparse, CXSparse, SchurSpecializations, C++11, OpenMP, Multithreading]
-- Configuring done
-- Generating done
-- Build files have been written to: /home/jxl/third_softwares/Sophus-master/Sophus/build_dir
jxl@dell:~/third_softwares/Sophus-master/Sophus/build_dir$ 

I have no idea why it will find ceres. If I ignore this mismatch, continue to make Sophus, there are some errors similar to @JHzss in this question. Maybe it is because the built ceres depend eigen version is not the same with my custom.
BTW, on another pc, which is ubuntu18.04, eigen is 3.3.7, make Sophus successfully without any error.
Jiao

@NikolausDemmel
Copy link
Contributor

Ceres is just used in one of the tests. You can uncomment the corresponding part in the cmakelists and not build that test.

Or you rebuild ceres from scratch with the right eigen version. I had some success with passing EIGEN_INCLUDE_DIR_HINTS with the correct eigen directory to cmake when building ceres, but maybe depends on the ceres version.

@fengweichangzi
Copy link

I got the similar error "can not find eigen" with cmake 3.22.5, eigen 3.40, VS2019.
Then I did the following as @narutojxl mentioned:
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake_modules") in Sophus/CMakeLists.txt:

Finally, cmake can find eigen now.

I did not the reason but it worked. Maybe the "CMAKeLists.txt" should upadate.

@NikolausDemmel
Copy link
Contributor

Are you using Sophus from another project with add_subdirectory?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

8 participants