C++ CFLAGS=-std=c++;11-O3-墙壁-makefile中未识别学究
我有一个makefile,在这里我编译了许多cpp文件以生成不同的可执行文件C++ CFLAGS=-std=c++;11-O3-墙壁-makefile中未识别学究,c++,c++11,makefile,C++,C++11,Makefile,我有一个makefile,在这里我编译了许多cpp文件以生成不同的可执行文件 CFLAGS=-std=c++11 -O3 -Wall -pedantic
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
g++-c-o auto_variables.o auto_variables.cpp
Auto.ActualPosial.CP:8:27:错误:ISO C++禁止声明“和”,没有类型[fime]。
自动求和(整数x,整数y)->整数
^
auto_variables.cpp:8:27:错误:“sum”的顶级声明指定“auto”
auto_variables.cpp:8:27:错误:尾部返回类型仅适用于-std=c++11或-std=gnu++11
auto_variables.cpp:在函数“int main()”中:
auto_variables.cpp:16:8:错误:“var_1”未命名类型
自动变量1=5;
^
auto_variables.cpp:18:8:错误:“var_2”未命名类型
自动变量_2='c';
^
auto_variables.cpp:20:16:错误:“var_1”未在此作用域中声明
std::cout我建议使用cxflags
而不是CFLAGS
CXXFLAGS=-std=c++11 -O3 -Wall -pedantic
<> >代码> cFLAGs<代码>,C代码为“>代码> CXXFLAGG/<代码>,用于C++标志。
CXXFLAGS=-std=c++11 -O3 -Wall -pedantic
还有,我不清楚你说的是什么意思:
CC=g++1
那是打字错误吗?我猜你是想用
CC=g++
与前面的更改保持一致,您应该将其更改为:
CXX=g++
然后,将使用$(CC)$(CFLAS)
的所有位置更改为$(CXX)$(cxflags)
我建议使用cxflags
而不是CFLAGS
CXXFLAGS=-std=c++11 -O3 -Wall -pedantic
<> >代码> cFLAGs<代码>,C代码为“>代码> CXXFLAGG/<代码>,用于C++标志。
CXXFLAGS=-std=c++11 -O3 -Wall -pedantic
还有,我不清楚你说的是什么意思:
CC=g++1
那是打字错误吗?我猜你是想用
CC=g++
与前面的更改保持一致,您应该将其更改为:
CXX=g++
然后,将使用$(CC)$(CFLAS)
的所有位置更改为$(CXX)$(cxflags)
这是因为您误用Make
< C++ >使用正确的变量,如:<代码> CXXFLAGG/<代码> .<
CXXFLAGS=-std=c++11 -O3 -Wall -pedantic
至少在开始时,你不需要设置任何其他内容
这将确保您使用的是正确的隐式规则。如果这样做没有帮助,请制作一个显示代码的脚本。发生这种情况是因为您误用了make
< C++ >使用正确的变量,如:<代码> CXXFLAGG/<代码> .<
CXXFLAGS=-std=c++11 -O3 -Wall -pedantic
至少在开始时,你不需要设置任何其他内容
这将确保您使用的是正确的隐式规则。如果这不起作用,也可以制作一个显示代码的图标。您使用CC
和CFLAGS
而不是CXX
和cxflags
,并将LDFLAGS
设置为空,这让我有点不安。你这样做有充分的理由吗?你应该展示一个小得多的例子,也许还有给你编译器错误的代码。o文件也是目标,向它们添加cflags,或者设置cxflags
并使用隐式规则。你使用CC
和cflags
而不是CXX
和cxflags
,这让我有点困扰,并将LDFLAGS
设置为空。你这样做有充分的理由吗?您应该展示一个小得多的示例,可能还有导致编译器错误的代码。o文件也是目标,向它们添加cflags,或者设置cxflags
并使用隐式规则。