Inquisitive
Super Moderator
I'm playing with GNU C on Ubuntu 12.04 LTS on a 64bit system.
When I compile the program using a makefile I get an error:
"undefined reference to `pow'
collect2: ld returned 1 exit status"
But if compiled with the same command line that is used in the makefile but use it in a terminal window it compiles without errors and functions normally. What is going on here?
Here is the makefile.
Here is the C program that is giving the math.h pow error.
Any ideas as to how to solve this?
Thanks!
When I compile the program using a makefile I get an error:
"undefined reference to `pow'
collect2: ld returned 1 exit status"
But if compiled with the same command line that is used in the makefile but use it in a terminal window it compiles without errors and functions normally. What is going on here?
Here is the makefile.
Makefile:
# build an executable named fig04_06 from fig04_06.c
all: fig04_06
gcc -g -Wall fig04_06.c -lm -o fig04_06
clean:
$(RM) fig04_06
Here is the C program that is giving the math.h pow error.
Code:
// Fig. 4.6: fig04_06.c
// Calculating compound interest
#include <stdio.h>
#include <math.h>
// function main begins program execution
int main( void )
{
double amount; // amount on deposit
double principal = 1000.0; // starting principal
double rate = .05; // annual interest rate
unsigned int year; // year counter
// output table column heads
printf( "%4s%21s\n", "Year", "Amount on deposit" );
// calculate amount on depposit for each of ten years
for ( year = 1; year <= 10; ++year ) {
// calculate new amount for specified year
amount = principal * pow( 1.0 + rate, year );
// output one table row
printf( "%4u%21.2f\n", year, amount );
} // end for
return 0;
} // end function main
Any ideas as to how to solve this?
Thanks!