This bugzilla service is closed. All entries have been migrated to
Bug 1102 - Linker error in MathFunctions.h when using -Ofast on gcc 4.7.2
Summary: Linker error in MathFunctions.h when using -Ofast on gcc 4.7.2
Alias: None
Product: Eigen
Classification: Unclassified
Component: Core - general (show other bugs)
Version: unspecified
Hardware: All All
: Normal Unknown
Assignee: Nobody
Depends on:
Reported: 2015-10-30 17:55 UTC by Graham Neubig
Modified: 2019-12-04 15:07 UTC (History)
5 users (show)

A simple example that can reproduce the error (413 bytes, application/x-gzip)
2015-10-30 17:55 UTC, Graham Neubig
no flags Details

Description Graham Neubig 2015-10-30 17:55:04 UTC
Created attachment 620 [details]
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
Comment 1 Gael Guennebaud 2015-10-30 21:27:15 UTC
Thank you for the detailed report. Fixed:
Comment 2 Silvio Traversaro 2015-11-01 00:19:00 UTC
I don't know if it is directly related, but we are experiencing several problem similar to the one explained this bug. 

Here's  a log from one CI run on Visual Studio 2012 using the latest Eigen from the default branch: 

In particular it is strange the syntax (isinf./) at line 880 of Eigen/src/Core/MathFunctions.h  .
Comment 3 Gael Guennebaud 2015-11-02 15:10:53 UTC
arf, nothing related just a typo
Comment 4 Nobody 2019-12-04 15:07:43 UTC
-- GitLab Migration Automatic Message --

This bug has been migrated to's GitLab instance and has been closed from further activity.

You can subscribe and participate further through the new bug through this link to our GitLab instance:

Note You need to log in before you can comment on or make changes to this bug.