error using eigen
Hello all! I wanted to use Eigen library with my ROS project. I installed eigen3 and followed the instruction at https://github.com/ros/cmake_modules/blob/0.3-devel/README.md#usage but when I try to run catkinmake it returns many errors which are mainly pointing to eigen library itself. I even tested eigen library with a non-ros C++ program and it works fine. Errors returned from catkinmake are very long but the last part of it are as follows:
In file included from /usr/include/eigen3/Eigen/Core:347:0,
from /usr/include/eigen3/Eigen/Dense:1,
from /home/hossein/multi_ws/src/event_formation/include/kalman.h:1,
from/home/hossein/multi_ws/src/event_formation/src/Kalman.cpp:6:/usr/include/eigen3/Eigen/src/Core/CwiseBinaryOp.h: In instantiation of ‘Eigen::CwiseBinaryOp<BinaryOp, Lhs, Rhs>::CwiseBinaryOp(const Lhs&, const Rhs&, const BinaryOp&) [with BinaryOp = Eigen::internal::scalar_sum_op<float, double>; LhsType = const Eigen::Matrix<float, 3, 3>; RhsType = const Eigen::Matrix<double, 3, 3>; Eigen::CwiseBinaryOp<BinaryOp, Lhs, Rhs>::Lhs = Eigen::Matrix<float, 3, 3>; Eigen::CwiseBinaryOp<BinaryOp, Lhs, Rhs>::Rhs = Eigen::Matrix<double, 3, 3>]’:/usr/include/eigen3/Eigen/src/plugins/CommonCwiseBinaryOps.h:27:1: required from ‘const Eigen::CwiseBinaryOp<Eigen::internal::scalar_sum_op<typename Eigen::internal::traits<T>::Scalar, typename Eigen::internal::traits<OtherDerived>::Scalar>, const Derived, const OtherDerived> Eigen::MatrixBase<Derived>::operator+(const Eigen::MatrixBase<OtherDerived>&) const [with OtherDerived = Eigen::Matrix<double, 3, 3>; Derived = Eigen::Matrix<float, 3, 3>; typename Eigen::internal::traits<OtherDerived>::Scalar = double; typename Eigen::internal::traits<T>::Scalar = float]’/home/hossein/multi_ws/src/event_formation/src/Kalman.cpp:64:58: required from here
/usr/include/eigen3/Eigen/src/Core/CwiseBinaryOp.h:107:7: error: static assertion failed: YOU_MIXED_DIFFERENT_NUMERIC_TYPES__YOU_NEED_TO_USE_THE_CAST_METHOD_OF_MATRIXBASE_TO_CAST_NUMERIC_TYPES_EXPLICITLY
EIGEN_CHECK_BINARY_COMPATIBILIY(BinaryOp,typename Lhs::Scalar,typename Rhs::Scalar);
^
event_formation/CMakeFiles/event_formation.dir/build.make:86: recipe for target 'event_formation/CMakeFiles/event_formation.dir/src/Kalman.cpp.o' failed
make[2]: *** [event_formation/CMakeFiles/event_formation.dir/src/Kalman.cpp.o] Error 1
CMakeFiles/Makefile2:3102: recipe for target 'event_formation/CMakeFiles/event_formation.dir/all' failed
make[1]: *** [event_formation/CMakeFiles/event_formation.dir/all] Error 2
Makefile:140: recipe for target 'all' failed
make: *** [all] Error 2
Invoking "make -j4 -l4" failed
The CMakeLists.txr is as follows:
cmake_minimum_required(VERSION 2.8.3)
project(event_formation)
find_package(catkin REQUIRED COMPONENTS
roscpp
rospy
std_msgs
message_generation
)
find_package(cmake_modules REQUIRED)
find_package(Eigen REQUIRED)
add_message_files(
FILES
event.msg
)
generate_messages(
DEPENDENCIES
std_msgs
)
catkin_package(
INCLUDE_DIRS include
CATKIN_DEPENDS roscpp rospy std_msgs
DEPENDS system_lib
DEPENDS Eigen
)
include_directories(
include
${catkin_INCLUDE_DIRS}
)
include_directories(
include
${catkin_LIBRARIES}
${Eigen_INCLUDE_DIRS}
)
add_executable(event_formation src/main.cpp src/Kalman.cpp)
target_link_libraries(event_formation
${catkin_LIBRARIES}
)
Asked by hossein on 2019-12-02 17:29:10 UTC
Answers
I am not much familiar with eigen errors. Maybe the dependency should be to Eigen3
instead of Eigen since you have installed eigen3.
find_package(Eigen3 REQUIRED)
On another note, dont forget to include the eigen directories:
include_directories(SYSTEM ${EIGEN3_INCLUDE_DIR})
and link your target with the eigen libraries:
target_link_libraries(your_target ${catkin_LIBRARIES} ${EIGEN3_LIBRARIES})
Also since you are generating a custom msg add the message_runtime as dependency:
catkin_package(
INCLUDE_DIRS include
# LIBRARIES event_formation
CATKIN_DEPENDS roscpp rospy std_msgs message_runtime
DEPENDS system_lib
DEPENDS Eigen3
)
Asked by pavel92 on 2019-12-04 05:10:41 UTC
Comments
Thanks. The problem was not from CMakeLists.txt file.
Asked by hossein on 2019-12-04 18:45:43 UTC
Thanks every one for your help. I dug into my code as @Choco and @mgluhrer said and found out that the problem was because of assigning a wrong type of matrix to one of my matrices in my calculations. Although it's a bit odd for me that a small mistake leads to this long error in eigen library.
Asked by hossein on 2019-12-04 18:42:12 UTC
Comments
This doesn't seem like a linking or build error, meaning eigen was added to your project successfully. And for the rest I think stack overflow would be right place to ask such questions. Also people can't really help you much with just error message without looking at actual code.
Asked by Choco93 on 2019-12-03 03:45:37 UTC
Please post the contents of your
CMakeLists.txt
fileAsked by pavel92 on 2019-12-03 04:26:15 UTC
Thank you @Choco93 and @pavel92 for your answers. I added the CMakeLists.txt to my question.
Asked by hossein on 2019-12-03 08:50:05 UTC
as @Choco93 said: This seems to be not ROS related. There error provided is:
and seems to stem from `Kalman.cpp:64.
Try googling for that. This delivers e.g. https://stackoverflow.com/questions/23946658/error-mixing-types-with-eigen-matrices
Asked by mgruhler on 2019-12-03 09:11:46 UTC