MKL linking error: multiple definitions

Submitted by Janick Martinez Esturo

Assigned to Nobody

Link to original bugzilla bug (#486)
Version: 3.1

Description

Hi!

I'm having a lot of "multiple definitions" errors when linking of object files that are compiled using -DEIGEN_USE_MKL_ALL, e.g. when using two files

//test.cpp
#include <Eigen/QR>

int test();

int main() {
test();
}

//test2.cpp
#include <Eigen/QR>

int test() {
}

some compute() methods for the mkl operations are defined multiple times, which gives these errors on link time:

/tmp/cc8YsEVj.o: In function Eigen::ColPivHouseholderQR<Eigen::Matrix<double, -1, -1, 0, -1, -1> >::compute(Eigen::Matrix<double, -1, -1, 0, -1, -1> const&)': test2.cpp:(.text+0x0): multiple definition of Eigen::ColPivHouseholderQR<Eigen::Matrix<double, -1, -1, 0, -1, -1> >::compute(Eigen::Matrix<double, -1, -1, 0, -1, -1> const&)'
/tmp/ccz28417.o:test.cpp:(.text+0x0): first defined here
/tmp/cc8YsEVj.o: In function Eigen::ColPivHouseholderQR<Eigen::Matrix<float, -1, -1, 0, -1, -1> >::compute(Eigen::Matrix<float, -1, -1, 0, -1, -1> const&)': test2.cpp:(.text+0x350): multiple definition of Eigen::ColPivHouseholderQR<Eigen::Matrix<float, -1, -1, 0, -1, -1> >::compute(Eigen::Matrix<float, -1, -1, 0, -1, -1> const&)'
/tmp/ccz28417.o:test.cpp:(.text+0x350): first defined here
/tmp/cc8YsEVj.o: In function Eigen::ColPivHouseholderQR<Eigen::Matrix<std::complex<double>, -1, -1, 0, -1, -1> >::compute(Eigen::Matrix<std::complex<double>, -1, -1, 0, -1, -1> const&)': test2.cpp:(.text+0x68a): multiple definition of Eigen::ColPivHouseholderQR<Eigen::Matrix<std::complex<double>, -1, -1, 0, -1, -1> >::compute(Eigen::Matrix<std::complex<double>, -1, -1, 0, -1, -1> const&)'
/tmp/ccz28417.o:test.cpp:(.text+0x68a): first defined here
/tmp/cc8YsEVj.o: In function Eigen::ColPivHouseholderQR<Eigen::Matrix<std::complex<float>, -1, -1, 0, -1, -1> >::compute(Eigen::Matrix<std::complex<float>, -1, -1, 0, -1, -1> const&)': test2.cpp:(.text+0x9da): multiple definition of Eigen::ColPivHouseholderQR<Eigen::Matrix<std::complex<float>, -1, -1, 0, -1, -1> >::compute(Eigen::Matrix<std::complex<float>, -1, -1, 0, -1, -1> const&)'
/tmp/ccz28417.o:test.cpp:(.text+0x9da): first defined here
/tmp/cc8YsEVj.o: In function Eigen::ColPivHouseholderQR<Eigen::Matrix<double, -1, -1, 1, -1, -1> >::compute(Eigen::Matrix<double, -1, -1, 1, -1, -1> const&)': test2.cpp:(.text+0xd14): multiple definition of Eigen::ColPivHouseholderQR<Eigen::Matrix<double, -1, -1, 1, -1, -1> >::compute(Eigen::Matrix<double, -1, -1, 1, -1, -1> const&)'
/tmp/ccz28417.o:test.cpp:(.text+0xd14): first defined here
/tmp/cc8YsEVj.o: In function Eigen::ColPivHouseholderQR<Eigen::Matrix<float, -1, -1, 1, -1, -1> >::compute(Eigen::Matrix<float, -1, -1, 1, -1, -1> const&)': test2.cpp:(.text+0x1064): multiple definition of Eigen::ColPivHouseholderQR<Eigen::Matrix<float, -1, -1, 1, -1, -1> >::compute(Eigen::Matrix<float, -1, -1, 1, -1, -1> const&)'
/tmp/ccz28417.o:test.cpp:(.text+0x1064): first defined here
/tmp/cc8YsEVj.o: In function Eigen::ColPivHouseholderQR<Eigen::Matrix<std::complex<double>, -1, -1, 1, -1, -1> >::compute(Eigen::Matrix<std::complex<double>, -1, -1, 1, -1, -1> const&)': test2.cpp:(.text+0x139e): multiple definition of Eigen::ColPivHouseholderQR<Eigen::Matrix<std::complex<double>, -1, -1, 1, -1, -1> >::compute(Eigen::Matrix<std::complex<double>, -1, -1, 1, -1, -1> const&)'
/tmp/ccz28417.o:test.cpp:(.text+0x139e): first defined here
/tmp/cc8YsEVj.o: In function Eigen::ColPivHouseholderQR<Eigen::Matrix<std::complex<float>, -1, -1, 1, -1, -1> >::compute(Eigen::Matrix<std::complex<float>, -1, -1, 1, -1, -1> const&)': test2.cpp:(.text+0x16ee): multiple definition of Eigen::ColPivHouseholderQR<Eigen::Matrix<std::complex<float>, -1, -1, 1, -1, -1> >::compute(Eigen::Matrix<std::complex<float>, -1, -1, 1, -1, -1> const&)'
/tmp/ccz28417.o:test.cpp:(.text+0x16ee): first defined here
collect2: error: ld returned 1 exit status

The same also happens for all other MKL related comptations of the LAPACKE interface. Perhaps this is a known problem, but is should be possible to link two files compiled with EIGEN_USE_MKL_ALL, am I right. Although the method definitions are the same, shouldn't the compiler figure this out by itself?
I'm using gcc-4.7.1, but the same errors occure with clang++-3.1.

Greets Janick

Edited by Eigen Bugzilla