Questions tagged [libm]

Under Linux, the mathematical functions (as declared in math.h) are bundled separately in the mathematical library libm. If any of them is used, the linker must be given the directive -lm.

Taken from here.

72 questions
165
votes
5 answers

Why am I getting "undefined reference to sqrt" error even though I include math.h header?

I'm very new to C and I have this code: #include #include int main(void) { double x = 0.5; double result = sqrt(x); printf("The square root of %lf is %lf\n", x, result); return 0; } But when I compile this with: gcc…
Ant's
  • 13,545
  • 27
  • 98
  • 148
17
votes
1 answer

Where is gnu lib math (libm) source code

I want to download and compile the source code for libm (GNU's may library). Can someone point me to the correct location / repository?
user1205476
  • 391
  • 1
  • 3
  • 12
12
votes
3 answers

I do *not* want correct rounding for function exp

The GCC implementation of the C mathematical library on Debian systems has apparently an (IEEE 754-2008)-compliant implementation of the function exp, implying that rounding shall always be correct: (from Wikipedia) The IEEE floating point standard…
Rémi Peyre
  • 410
  • 3
  • 12
11
votes
1 answer

What functions is the libm intended for?

As far as I know some math functions are contained in libc, while others are in libm. I've discovered that experimentally: $ nm --dynamic --defined-only /lib/x86_64-linux-gnu/libm.so.6 | grep -w abs $ nm --dynamic --defined-only…
Alexey
  • 710
  • 3
  • 7
  • 19
11
votes
3 answers

Can CMake detect if I need to link to libm when using pow in C?

With some compilers, using pow and certain other functions in a C program requires linking to the m library. However, some compilers don't require this and would error out on linking to the m library. An almost identical situation exists for C++…
LB--
  • 2,506
  • 1
  • 38
  • 76
9
votes
3 answers

gcc gives error while using fmod()

Sample code for fmod: #include #include int main(void) { double x = 0.14527, y = 3.14159; printf("fmod(x, y) = %.6lf\n", fmod(x, y)); return 0; } Compiling: $ gcc main.c -o main I…
mohit
  • 1,011
  • 2
  • 16
  • 26
9
votes
1 answer

what is libc? what are the functions it includes? how can we get the source code of it?

As per Wikipedia there are many variants of standard C library based on operating system and compilers. Ref: http://en.wikipedia.org/wiki/C_standard_library But I want to understand that how plenty of functions which are declared in different…
Yash
  • 173
  • 2
  • 13
9
votes
0 answers

NDK: libm static linking

I have a problem during try to compile sources with recent android-9 x86 platform. Primary question: why static library libm.a and dynamic libm.so are different? Problem is i've try to…
wwakabobik
  • 91
  • 4
8
votes
4 answers

How can I use complex.h for Android NDK?

I have native source code written in C that I would like to run on my Android device (Nexus 7). I already successfully did lots of research and online tutorials on running native code on Android using Android NDK. I gained quite some knowledge on…
Sam
  • 314
  • 3
  • 8
7
votes
2 answers

Compiling: //lib/x86_64-linux-gnu/libm.so.6: error adding symbols: DSO missing

I am having trouble compiling code intended for 32bit unix system on my 64bit Ubuntu, Linux. Does anyone have any ideas what may be the problem? gcc main.o test.o render.o transform.o model.o vector.o color.o -o the_thing -lSDL /usr/bin/ld:…
Cat Matrix
  • 81
  • 1
  • 1
  • 2
6
votes
3 answers

why there is no static library for math functions?

Is it a standard to have only dynamic libraries mostly without their static version? I am particularly asking about math library. In my fedora 17 (linux machine on Intel 32 processor), I have latest gcc and it has libm-2.15.so and symbolic link file…
KawaiKx
  • 9,558
  • 19
  • 72
  • 111
5
votes
2 answers

Why it didn't need link libm?

#include #include int main() { printf("%f", roundf(3.14)); } I compile above code (hasn't use -lm), add use ldd a.out, the result is linux-vdso.so.1 => (0x00007fffab9ff000) libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6…
snyh
  • 1,225
  • 14
  • 19
5
votes
2 answers

Libm optimised for ARM?

Is there a libm (libmath) that is optimised for ARM(v6) processors? I was looking at the GNU implementation and it doesn't seem to be optimised (but it does have x86 ones). It seems that most implementations of libm do not have ARM specific…
Kristina
  • 15,859
  • 29
  • 111
  • 181
4
votes
4 answers

Floating point inconsistencies after upgrading libc/libm

I recently upgraded my OS from Debian 9 to Debian 11. I have a bunch of servers running a simulation and one subset produces a certain result and another subset produces a different result. This did not used to happen with Debian 9. I have produced…
user3856370
  • 199
  • 9
4
votes
2 answers

jq: error: round/0 is not defined at

round function in jq doesn't work. $ jq '10.01 | round' jq: error: round/0 is not defined at , line 1: 10.01 | round jq: 1 compile error $ jq --help jq - commandline JSON processor [version 1.5-1-a5b5cbe] What I need to do?
1
2 3 4 5