Click here to Skip to main content
15,886,518 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am running into a problem with the pow function in my program. The function is part of a for loop and here is the code section:

for( year = 1; year <= 10; ++year)
{
amount = principal * pow( 1.0 + rate, year);
printf( "%4u%21.2f\n", year, amount);
}

When I run my program I get the following error message:

/tmp/cc9xIlqs.o: In function 'main':
main.c: (.text+0x84): undefined reference to 'pow'
collect2: error: ld returned 1 exit status

Can anyone provide help with this?
Posted

Try adding the -lm switch to your gcc command to load the math library:
gcc MyProgram.c -o MyProgram -lm
 
Share this answer
 
Thanks. My fonts have made that suggestion look like a number 1 instead of a lower case l. It took me a few tries before I even made the connection. Thanks for the help.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900