2017-02-22 65 views
0

我在there上學習makefile的教程。 對於Makefile文件2,有正確的代碼:爲什麼Makefile不能像這樣工作?

CC=gcc 
CFLAGS=-I. 

hellomake: hellomake.o hellofunc.o 
    $(CC) -o hellomake hellomake.o hellofunc.o -I. 

爲什麼不能像這樣工作:

hellomake: hellomake.o hellofunc.o 
    gcc -o hellomake hellomake.o hellofunc.o -I. 

及以下錯誤:

hellomake.c:2:10: error: 'hellomake.h' file not found with <angled> include; use 
     "quotes" instead 
#include <hellomake.h> 
     ^~~~~~~~~~~~~ 
     "hellomake.h" 
1 error generated. 

回答

3

在第一「working」makefile使用

CFLAGS=-I. 

將源文件編譯爲目標文件時使用,並告知編譯器(及其預編譯器)應將當前目錄添加到系統頭文件目錄列表中。

第二個makefile沒有這樣做。編譯器在創建目標文件時沒有額外的標誌。所以編譯器不會將當前目錄添加到目錄列表中。

您在第二個makefile中的-I選項是當鏈接。到那時,對象文件已經被創建(如果沒有錯誤,應該已經創建),並且鏈接器完全不使用-I標誌。

+1

只要知道'CFLAGS'是一個預先定義的宏。 –

相關問題