c - "undefined reference to `pow'" even with math.h and the library link -lm -


i'm using math.h , -lm option compile. have tried of:

gcc -o ssf ssf_tb.c ssf.c -lm gcc -o ssf ssf_tb.c -lm ssf.c    gcc -o -lm ssf -lm ssf_tb.c ssf.c 

but error:

undefined reference 'pow'   

happens on cases.

put -lm @ end of line.

gcc processes arguments specify inputs final program in order appear on command line. -lm argument passed linker, , ssf.c argument, example, compiled, , resulting object file passed linker.

the linker processes inputs in order. when sees library, -lm specifies, looks see if library supplies symbols that linker needs. if so, copies modules symbols library , builds them program. when linker sees object module, builds object module program. after bringing object module program, linker not go , see if needs earlier libraries.

because listed library first, linker did not see needed library. if list object module first, linker bring object module program. in process of doing this, linker make list of undefined symbols object needs. then, when linker sees library, see library supplies definitions symbols, , bring modules symbols program.


Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -