我在 kubuntu 上使用 g 7.5.0 / GNU make for C 。我的檔案結構:
bin
| .o files
header
|archiver.h
source
|main.cpp
|archiver.cpp
makefile
我希望我的源檔案能夠檢測頭檔案,而不必執行 #include "../header/archiver.h"。我試過使用:
g -I/header
但這不起作用。我得到錯誤:
g : fatal error: no input files.
請求的生成檔案
CC = g
CFLAGS = -c -Wall
objects = bin/main.o bin/archiver.o
all : $(objects)
$(CC) -o build $(objects)
bin/%.o : source/%.cpp
$(CC) $(CFLAGS) $?
mv *.o bin
.PHONY : clean
clean :
rm -rf all $(objects)
uj5u.com熱心網友回復:
命令
g -I<header-dir>
g 正如您所假設的那樣,不會通過后續呼叫更改包含搜索路徑的任何默認設定。
您需要為每個單獨的 c 呼叫傳遞該編譯器標志,這些呼叫是make根據您的makefile.
后者是您需要適應的,最好使用預定義的 makefile 變數,如CXXFLAGSor CXXINCLUDES(查看 GNU-make 檔案以獲取詳細資訊)。
對于您的具體情況
CFLAGS = -c -Wall -I./header
應該管用。
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/477973.html
上一篇:如何使用mdfreader從AWSS3讀取.dat檔案
下一篇:如何使用sscanf決議浮點數
