search instagram arrow-down

Archives

Categories

Meta

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$

 

 

Leave a Reply
Your email address will not be published. Required fields are marked *

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: