Seems like the user who found the solution never shared it later. For guys who are trying to find the solution just add the math library explicitly and also add -ldl
So -lm and -ldl in the gcc line you are compiling and it should go just fine.
Alternatively, in most cases you can also explicitly define CFLAGS and alleviate the issue that way. These are just two ways of solving,
Example:
user@compiler-shell$ EXPORT CFLAGS=" -g -O2 -lm -ldl -Wall -Wpointer-arith -finline-functions -ffast-math -funroll-all-loops";
Answer from Chandan Maddanna on askubuntu.comSeems like the user who found the solution never shared it later. For guys who are trying to find the solution just add the math library explicitly and also add -ldl
So -lm and -ldl in the gcc line you are compiling and it should go just fine.
Alternatively, in most cases you can also explicitly define CFLAGS and alleviate the issue that way. These are just two ways of solving,
Example:
user@compiler-shell$ EXPORT CFLAGS=" -g -O2 -lm -ldl -Wall -Wpointer-arith -finline-functions -ffast-math -funroll-all-loops";
I've added -lm into CMakeLists.txt where libraries are being assigned. It's working now.
You need to compile with the link flag -lm, like this:
gcc fib.c -lm -o fibo
This will tell gcc to link your code against the math lib. Just be sure to put the flag after the objects you want to link.
Add -lm to your link options, since pow() and floor() are part of the math library:
gcc fib.c -o fibo -lm
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.
C++ is not ABI stable: when you build something on your machine it will work on your machine only. This is because the binary produced is specific to your architecture.
In this case it seems that there is a mismatch of the C standard library (libc).
If you want to don't depend from the system implementation of the standard C++ you can try to statically link to the standard library.
If you use gcc or clang try -static compiler option.
The solution to your problem would be compile your program to the target platform.