Linking to eigen cross product requires including the right eigen header

Alec Jacobson

February 03, 2012

weblog/

We were foiled for a while today by a strange eigen error. We successfully compiled a function that called eigen's cross product function. But then linking to our compiled function resulted in linker errors within the cross product function. Our errors looked like this
"Eigen::MatrixBase<Eigen::Matrix<double, 1, 3, 1, 1, 3> >::cross_product_return_type<Eigen::Matrix<double, 1, 3, 1, 1, 3> >::type Eigen::MatrixBase<Eigen::Matrix<double, 1, 3, 1, 1, 3> >::cross<Eigen::Matrix<double, 1, 3, 1, 1, 3> >(Eigen::MatrixBase<Eigen::Matrix<double, 1, 3, 1, 1, 3> > const&) const", referenced from:
      void igl::per_face_normals<Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -1, -1, 0, -1, -1> >(Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> >&)in libigl.a(per_face_normals.o)
The workaround to this bug in eigen is to be sure to include the following header in the function compiling with the cross product call:
#include <Eigen/Geometry>