Hello,
I am trying to use make to compile and link two simple C programs in linux. Here is the two programs.
combine1.c
Code:
//combine1.c
#include <stdio.h>
int main(void)
{
int n;
printf("This is a test\n");
printf("n=%d\n", input(n));
printf("Done");
return 0;
}
combine2.c
Code:
//combine2.c
input(int n)
{
n = 10;
return n;
}
I can compile and link these two using gcc without any trouble:
Code:
gcc -o combine combine1.c combine2.c
I want to compile and link the two using make but I don't think I am doing my Makefile correctly. Can someone explain how to do this? Here is what I have for my Makefile:
Code:
project1: combine1.o
gcc -o project1 combine1.o
combine1.o: combine1.c combine2.c
gcc -c combine1.c
clean:
rm project1 combine1.o
When I type $make
I get the following:
Code:
combine1.o: In function `main':
combine1.c:(.text+0x1b): undefined reference to `input'
collect2: ld returned 1 exit status
make: *** [project1] Error 1
Thanks for any help.