1
我具有簡單的結構爲:未定義參照主,生成文件
sample2Make$ ls
ADD DIV inc_print.h main.c makefile multiplication.o printer.o response.o subtraction.o addition.o division.o inc_resp.h main.o MUL printer.c response.c SUB
其中ADD,DIV,SUB,MUL是含有用於所述操作的源文件和一個頭文件子目錄。生成文件是:
app: addition.o subtraction.o multiplication.o division.o response.o
gcc -o app response.o addition.o subtraction.o multiplication.o division.o
response.o: inc_resp.h inc_print.h response.c printer.c main.c
gcc -c response.c printer.c main.c
addition.o: ADD/inc_add.h ADD/addition.c
gcc -c ADD/addition.c
subtraction.o: SUB/inc_sub.h SUB/subtraction.c
gcc -c SUB/subtraction.c
multiplication.o: MUL/inc_mul.h MUL/multiplication.c
gcc -c MUL/multiplication.c
division.o: DIV/inc_div.h DIV/division.c
gcc -c DIV/division.c
頭文件只是聲明其各自的功能。現在寫命令後:
sample2Make$ make -f makefile
我得到的輸出是:
gcc -c ADD/addition.c
gcc -c SUB/subtraction.c
gcc -c MUL/multiplication.c
gcc -c DIV/division.c
gcc -c response.c printer.c main.c
gcc -o app addition.o subtraction.o multiplication.o division.o response.o
/usr/lib/gcc/i686-linux-gnu/4.9/../../../i386-linux-gnu/crt1.o: In function `_start':
/build/buildd/glibc-2.21/csu/../sysdeps/i386/start.S:111: undefined reference to `main'
collect2: error: ld returned 1 exit status
makefile:3: recipe for target 'app' failed
make: *** [app] Error 1
謝謝Sourav –
@TarangJain歡迎您。 :) –