Using C function in another function -
Using C function in another function -
i know has been answered, still can't work.
first.c
#include <stdio.h> #include "second.h" int main(void){ printf("%d\n", addone(5)); homecoming 0; } second.c
int addone(int a){ homecoming ++a; } second.h
int addone(int a); when run gcc -o executable first.c -wall shows me undefined reference addone
#include <stdio.h> #include "second.h"
include headers in second.c file , write makefile , compile make.
makefile:
cflags = -g -o -wall obj = first.o second.o # explicit rule required link. # compilation handled automatically. first: $(obj) $(cc) $(cflags) -o first $(obj) # declare both object files depend on header file. first.o second.o: second.h # conventionally 'make clean' removes 'make' creates. # not strictly required. .phony: clean clean: -rm -f first $(obj) you can't re-create , paste above; must alter both indented lines (the ones shell commands on them) indentation single hard tab character. if don't cryptic error message:
makefile:5: *** missing separator. stop.
first.c:
#include <stdio.h> #include "second.h" int main(void){ printf("%d\n", addone(5)); homecoming 0; } second.c
#include <stdio.h> #include "second.h" int addone(int a){ homecoming ++a; } second.h
#include <stdio.h> int addone(int a); c
Comments
Post a Comment