Hi List,
The question has been around for a long time: one often needs to compile Eigen code with multiple sets of compiler flags, and select at runtime between them, to take advantage of possibly-present CPU features such as AVX.
I always thought that I could simply compile the same Eigen-using code multiple times, with just a different namespace around my Eigen-using function each time, like
#include <Eigen/Core>
namespace avx_code_path {
void foo(Eigen::Vector4f& v)
{
v += v;
}
}
However, there is a problem with this: each of these code paths compiles Eigen code under the same, non-prefixed, Eigen namespace, each time with different resulting binary code due to different compiler flags. We are thus in a case of undefined behavior due to multiple definitions of inline functions (Eigen's funtions) actually being different.
I was hoping that this wasn't a big deal, that in practice the linker would do the right thing and let the code in each TU use the Eigen symbols defined in the same TU, so there would be no mixup. I was wrong... I'm seeing mixups on a basic testcase here, where my AVX codepath uses Eigen code from the non-AVX codepath.
So this approach doesn't work.