multiple definition of 'Eigen::internal::lapacke_helpers::to_lapack(long)' when including EIGEN_USE_LAPACKE
Summary
Trying to compile Eigen with EIGEN_USE_LAPACKE causes multiple definition of 'Eigen::internal::lapacke_helpers::to_lapack(long)'
Environment
- Operating System : Linux
- Architecture : x86_64
- Eigen Version : 3.3.9
- Compiler Version : g++ (GCC) 11.2.1 20220127 (Red Hat 11.2.1-9)
- Compile Flags : -DEIGEN_USE_LAPACKE -DEIGEN_USE_BLAS -llapacke -lblas
- Vector Extension :
Minimal Example
This bug happened in a larger code I am working on. I have designed a smaller problem that produces the error. Even though I don't include any calls to lapack(e) routines here the problem still occurs. it looks like a header guarding issue to me, as it doesn't occur if I work only in a single file.
Here is the minimal example:
dot.hh:
#ifndef DOT_HH
#define DOT_HH
#include <Eigen/Dense>
double dot( const Eigen::Ref<Eigen::VectorX<double>>& x, const Eigen::Ref<Eigen::VectorX<double>>& y );
#endif
dot.cc:
#include <Eigen/Dense>
#include <iostream>
#include "dot.hh"
double dot(const Eigen::Ref<Eigen::VectorX<double>>& x, const Eigen::Ref<Eigen::VectorX<double>>& y)
{
const double z = x.dot( y );
return z;
}
main.cc:
#include <Eigen/Dense>
#include <iostream>
#include "dot.hh"
int main()
{
Eigen::VectorX<double> x = Eigen::VectorX<double>::Random(10);
Eigen::VectorX<double> y = Eigen::VectorX<double>::Random(10);
const double z = dot( x, y );
std::cout << z << std::endl;
}
Steps to reproduce
g++ main.cc -o dot -I{path_to}/eigen/ -DEIGEN_USE_LAPACKE -DEIGEN_USE_BLAS -llapacke -lblas
Warning Messages
/usr/bin/ld: /tmp/ccPQIAqq.o: in function `Eigen::internal::lapacke_helpers::to_lapack(long)':
main.cc:(.text+0x0): multiple definition of `Eigen::internal::lapacke_helpers::to_lapack(long)'; /tmp/ccEVeOjc.o:dot.cc:(.text+0x0): first defined here
collect2: error: ld returned 1 exit status