hello,
I wonder how to reuse another *.c file's function. To have a try and demo, I have written following codes. Would you help me to have a look, and could you give me more suggestion about code reuse in c.
\\192.168.0.7\myproject\c-c++\linux\caller\caller.c
Code:
#include "../becalled/becalled.h"
int main(void)
{
int result= myAdd(1, 2);
printf("result=%d",result);
return 0;
}
\\192.168.0.7\myproject\c-c++\linux\caller\makefile
Code:
#include ../becalled/makefile #this want to be realized later.
run : caller.o
gcc -o run caller.o
caller.o : caller.c ../becalled/becalled ../becalled/becalled.h
gcc -c caller.c ../becalled/becalled.h ../becalled/becalled
clean :
rm run caller.o
\\192.168.0.7\myproject\c-c++\linux\becalled\makefile
Code:
becalled: becalled.o
gcc -o becalled becalled.o
becalled.o: becalled.c becalled.h
gcc -c becalled.c
\\192.168.0.7\myproject\c-c++\linux\becalled\becalled.c
Code:
int myAdd(int a, int b)
{
int result=0;
result=a+b;
return result;
}
int main(void)
{
return 0;
}
\\192.168.0.7\myproject\c-c++\linux\becalled\becalled.h
Code:
int myAdd(int a, int b);
make command output at:
Code:
root@linux-programming:~/myproject/c-c++/linux/caller# make
gcc -o run caller.o
caller.o: In function `main':
caller.c:(.text+0x13): undefined reference to `myAdd'
collect2: ld returned 1 exit status
make: *** [run] Error 1
Bookmarks