[英]Makefile for a project
我有一個使用正則表達式的項目的Makefile。 因此,我需要使用g ++-4.9和c ++ 11。
BIN = bin
OBJ = src/main.o src/time2.o src/except.o src/except2.o src/struct.o src/index.o
FLAGS = -lncurses
CC = g++-4.9 -std=c++11 -Wall -pedantic -Wno-long-long -O0 -ggdb
all: compile
run: compile
./$(BIN)
clean:
rm -f $(BIN) $(OBJ)
compile: $(OBJ)
$(CC) -o $(BIN) $(OBJ) $(FLAGS)
但是當我嘗試進行編譯時:
g++ -c -o src/main.o src/main.cpp In file included from /usr/include/c++/4.8/regex:35:0, from src/time2.h:16, from src/main.cpp:3: /usr/include/c++/4.8/bits/c++0x_warning.h:32:2: error: #error This file requires compiler and library support for the ISO C++ 2011 standard. This support is currently experimental, and must be enabled with the -std=c++11 or -std=gnu++11 compiler options. #error This file requires compiler and library support for the \\ ^ In file included from src/main.cpp:5:0: src/struct.h:99:18: error: 'regex' has not been declared bool isnamegood(regex x,const string& name); ^
所以我不明白怎么了,請您能幫我嗎?
問題是您的compile
目標已經取決於目標文件! 但是它們尚未構建,因此請嘗試找到構建它們的規則。 由於尚未定義自定義規則,因此它使用隱式規則 :
從n.cc,n.cpp或nC會自動以配方形式'$(CXX)$(CPPFLAGS)$(CXXFLAGS)-c'編譯C ++程序。 我們建議您對C ++源文件使用后綴“ .cc”而不是“ .C”。
該規則當然不會使用您在CC
設置的標志。 這解釋了為什么make
打印的gcc
命令行與您的CC
不匹配。 您可以通過使用--no-builtin-rules
運行make來進行測試,因為這會禁用所有隱式規則。
在這種情況下,一個好主意是使用-d
或--debug
運行make,我認為這應該顯示規則評估。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.