Search code examples
c++redhatcmath

Referencing std::pow() requires GLIBC2.29


I'm building on Ubuntu 20.04 and my program executed on RedHat 8 just fine until I included <cmath> and used std::pow(double, double). Now I get the following error on RedHat 8:

/lib64/libm.so.6: version `GLIBC_2.29' not found (required by /MyOwnLib.so)

What is so special about std::pow that it requires GLIBC 2.29? This function is very old. Can I somehow force the compiler on Ubuntu to "link" an older version?


Solution

  • There's nothing special. There's surprising little coordination between gcc, glibc and the linker people, despite them all being "GNU". To tell gcc that pow is not new, you can use asm (".symver pow, pow@GLIBC_2.2.5");. This will tell gcc that pow was available since glibc version 2.2.5, so gcc won't tell the linker that glibc 2.29 is needed. pow has been around for way longer of course, but 2.2.5 introduced this versioning scheme.

    The downside is that you miss out on the optimized version of pow from glibc 2.29, but that it intentional. That optimized version is missing from your RedHat 8 machine.

    And just to be complete: this is pow from libm, which is the math part of glibc. It is not std::pow(double, double) from C++. That tells us that std::pow(double, double) is a thin inline wrapper for pow, as expected.