我有一个makefile,可在其中编译许多cpp文件以制作不同的可执行文件。
CFLAGS=-std=c++11 -O3 -Wall -pedantic
CC=g++1
LDFLAGS=
all: auto_variables explict_kw for_each functor member_initializer member_initializer2 reference ref_ptr smart_pointers vector
auto_variables : auto_variables.o
$(CC) $(CFLAGS) auto_variables.o $(LDFLAGS) -o $@
explict_kw : explict_kw.o
$(CC) $(CFLAGS) explict_kw.o $(LDFLAGS) -o $@
for_each : for_each o
$(CC) $(CFLAGS) for_each.o $(LDFLAGS) -o $@
functor : functor.o
$(CC) $(CFLAGS) functor.o $(LDFLAGS) -o $@
member_initializer : member_initializer.o
$(CC) $(CFLAGS) member_initializer.o $(LDFLAGS) -o $@
member_initializer2 : member_initializer2.o
$(CC) $(CFLAGS) member_initializer2.o $(LDFLAGS) -o $@
reference : reference.o
$(CC) $(CFLAGS) reference.o $(LDFLAGS) -o $@
ref_ptr : ref_ptr.o
$(CC) $(CFLAGS) ref_ptr.o $(LDFLAGS) -o $@
smart_pointers : smart_pointers.o
$(CC) $(CFLAGS) smart_pointers.o $(LDFLAGS) -o $@
vector : vector.o
$(CC) $(CFLAGS) vector.o $(LDFLAGS) -o $@
clean:
rm -rf auto_variables explict_kw for_each functor member_initializer member_initializer2 reference ref_ptr smart_pointers vector
rm -rf *.o
我已将
-std=c++11
指定为CFLAGS
,但键入make时似乎没有采用该选项。g++ -c -o auto_variables.o auto_variables.cpp
auto_variables.cpp:8:27: error: ISO C++ forbids declaration of ‘sum’ with no type [-fpermissive]
auto sum(int x, int y) -> int
^
auto_variables.cpp:8:27: error: top-level declaration of ‘sum’ specifies ‘auto’
auto_variables.cpp:8:27: error: trailing return type only available with -std=c++11 or -std=gnu++11
auto_variables.cpp: In function ‘int main()’:
auto_variables.cpp:16:8: error: ‘var_1’ does not name a type
auto var_1 = 5;
^
auto_variables.cpp:18:8: error: ‘var_2’ does not name a type
auto var_2 = 'c';
^
auto_variables.cpp:20:16: error: ‘var_1’ was not declared in this scope
std::cout << var_1 << std::endl;
^
auto_variables.cpp:21:16: error: ‘var_2’ was not declared in this scope
std::cout << var_2 << std::endl;
^
auto_variables.cpp:23:8: error: ‘fun_sum’ does not name a type
auto fun_sum = [](int a, int b)
^
auto_variables.cpp:46:8: error: ‘itr’ does not name a type
auto itr = mapofStrs.begin();
^
auto_variables.cpp:47:9: error: ‘itr’ was not declared in this scope
while(itr != mapofStrs.end())
^
<builtin>: recipe for target 'auto_variables.o' failed
make: *** [auto_variables.o] Error 1
为什么会这样呢?
最佳答案
我建议使用CXXFLAGS
而不是CFLAGS
。CFLAGS
用于C标志,而CXXFLAGS
用于C ++标志。
CXXFLAGS=-std=c++11 -O3 -Wall -pedantic
另外,我不清楚您的意思是:
CC=g++1
那是错字吗?我怀疑你打算用
CC=g++
与之前的更改保持一致,您应该将其更改为:
CXX=g++
然后,将使用
$(CC) $(CFLAS)
的所有位置更改为$(CXX) $(CXXFLAGS)
。关于c++ - CFLAGS = -std = c++ 11 -O3 -Wall -pedantic在makefile中无法识别,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/35419113/