Linker error in MathFunctions.h when using -Ofast on gcc 4.7.2
Submitted by Graham Neubig
Assigned to Nobody
Link to original bugzilla bug (#1102)
Description
Created attachment 620
A simple example that can reproduce the error
I'm having a linker error when compiling a program with the latest development version of Eigen on gcc 4.7.2 (Debian Linux), only when the "-Ofast" option is enabled.
The error seems to be happening because the "isnan" and "isinf" functions in MathFunctions.h that use __builtin_isnan and __builtin_isinf (lines 890-895 in my version) are not inlined, and when Eigen is used in more than one cpp file, linking dies because the functions are multiply defined.
I've attached a simple example that can reproduce the error, and the error is as below:
classb.o: In function bool Eigen::numext::isnan<long double>(long double const&)': classb.cpp:(.text+0x0): multiple definition of
bool Eigen::numext::isnan<long double>(long double const&)'
classa.o:classa.cpp:(.text+0x0): first defined here
classb.o: In function bool Eigen::numext::isnan<double>(double const&)': classb.cpp:(.text+0x10): multiple definition of
bool Eigen::numext::isnan<double>(double const&)'
classa.o:classa.cpp:(.text+0x10): first defined here
classb.o: In function bool Eigen::numext::isnan<float>(float const&)': classb.cpp:(.text+0x20): multiple definition of
bool Eigen::numext::isnan<float>(float const&)'
classa.o:classa.cpp:(.text+0x20): first defined here
classb.o: In function bool Eigen::numext::isinf<double>(double const&)': classb.cpp:(.text+0x30): multiple definition of
bool Eigen::numext::isinf<double>(double const&)'
classa.o:classa.cpp:(.text+0x30): first defined here
classb.o: In function bool Eigen::numext::isinf<float>(float const&)': classb.cpp:(.text+0x50): multiple definition of
bool Eigen::numext::isinf<float>(float const&)'
classa.o:classa.cpp:(.text+0x50): first defined here
classb.o: In function bool Eigen::numext::isinf<long double>(long double const&)': classb.cpp:(.text+0x70): multiple definition of
bool Eigen::numext::isinf<long double>(long double const&)'
classa.o:classa.cpp:(.text+0x70): first defined here
collect2: error: ld returned 1 exit status
Attachment 620, "A simple example that can reproduce the error":
eigen-crash.tar.gz