Compiling C program including math functions

Generally you can compile C program as: gcc -Wall <programname.c> and for linking math functions such as pow, you need to specify the -lm option. Note that -lm option should be at the end of the command for Ubuntu11.10. So its better to always put the -lm option at the end of the gcc compilation.

Example:

daya@daya-Aspire-4937:~/Desktop/gcc$ gcc -Wall lab2ac.c
/tmp/ccHP22fZ.o: In function `main’:
lab2ac.c:(.text+0x8d): undefined reference to `pow’
collect2: ld returned 1 exit status
daya@daya-Aspire-4937:~/Desktop/gcc$ gcc -Wall lab2ac.c -o lab2ac.o -lm
daya@daya-Aspire-4937:~/Desktop/gcc$

 

 

Tutorial Sheets

Tutorial sheet-1

tutorials1