main.c:(.text+0x25): undefined reference to `reciprocal'

This is a sample program i was trying to compile this below c program to know about the make file. main.c ------ #include #include "reciprocal.h" int main(int argc,char **argv){ int i; i=atoi(argv[1]); printf("The Reciprocal of %d is %f\n ",i,reciprocal(i)); return 0; } reciprocal.c ------------ #include #include #include "reciprocal.h" double reciprocal(int i){ assert(i!=0); return 1.0/i; } reciprocal.h ------------ #include #ifdef __cplusplus extern "C"{ #endif extern double reciprocal(int i); #ifdef __cplusplus } #endif makefile -------- CFLAGS:=-o2 reciprocal: reciprocal.o main.o gcc $(CFLAGS) -o reciprocal.o main.o main.o: main.c reciprocal.h gcc $(CFLAGS) -c main.c -I ../include reciprocal.o: reciprocal.c reciprocal.h gcc $(CFLAGS) -c reciprocal.c -I ../include clean: rm -f *.o reciprocal when compiled as below it throws an error. % make > gcc -o2 -c reciprocal.c -I ../include gcc -o2 -c main.c -I ../include > gcc -o2 -o reciprocal.o main.o main.o: In function `main': > main.c:(.text+0x25): undefined reference to `reciprocal' collect2: ld > returned 1 exit status make: *** [reciprocal] Error 1 Please help me understand what is the reason for this error.

以上就是main.c:(.text+0x25): undefined reference to `reciprocal'的详细内容,更多请关注web前端其它相关文章!

赞(0) 打赏
未经允许不得转载:web前端首页 » CSS3 答疑

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

前端开发相关广告投放 更专业 更精准