Pages

jeudi 15 juillet 2010

compile c code in linux (some math functions used in the code)

I had a piece of c code and it worked in windows. Now i want to recompile it in linux.
When I launch :
gcc -o code code.c

It has error messages:
/home/tmp/cczz9Kqc.o: In function `wfptb':
readIAP0.c:(.text+0x197f): undefined reference to `exp'
readIAP0.c:(.text+0x1a27): undefined reference to `exp'
/home/tmp/cczz9Kqc.o: In function `decode':
readIAP0.c:(.text+0x2230): undefined reference to `pow'
readIAP0.c:(.text+0x235e): undefined reference to `pow'
collect2: ld a retourné 1 code d'état d'exécution

This suggests that some math functions can not be used, though "#include " is in the code. when I check:
man exp
in the linux terminal, there it suggests to link with -lm. It looks like that I need tell the linker to link with/usr/lib/libm.so.

So I recompile with:
gcc -o code code.c -lm

and the errors are gone.

Aucun commentaire:

Enregistrer un commentaire