繁体   English   中英

如何在makefile中设置compilingflags?

[英]how do I set compilingflags in a makefile?

我曾经在IDE中编程,但是最近切换到了vim和插件。 现在,我尝试为C ++项目编写一个makefile,但是如果我运行make我总是会收到错误消息

g++    -c -o *.o createOutput.cpp
In file included from /usr/include/c++/4.8/thread:35:0,
                 from createOutput.cpp:5:
/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 \
  ^

这是我的makefile:

CC = clang++

# compiler flags
CFLAGS = -O3 -Wall -Werror -std=c++11
CFLAGS_SFML = -lsfml-graphics -lsfml-window -lsfml-system

all: program.exe clean

program.exe: *.o
    $(CC) -o program.exe *.o $(CFLAGS) $(CFLAGS_SFML) 

getInput.o: getInput.cpp
    $(CC) -c getInput.cpp $(CFLAGS) 

createOutput.o: createOutput.cpp
    $(CC) -c createOutput.cpp $(CFLAGS) 

main.o: main.cpp
    $(CC) -c main.cpp $(CFLAGS)

.PHONY: clean
clean:
    rm *.o
    @echo clean done

我的错误在哪里? 为什么使用g++而不是clang 为什么不使用-std=c++11参数呢? 抱歉,对于初学者的问题,很遗憾,我找不到google解决方案。

您想要设置CXXFLAGS ,它会由make自动拾取(并发送到编译器( 例如 g++clang++ ))。

make试图使目标“*的.o”。

因此,相反,您可以显式指定源列表:

CC = clang++

#compiler flags
CFLAGS = -O3 -Wall -Werror -std=c++11
CFLAGS_SFML = -lsfml-graphics -lsfml-window -lsfml-system
SRCS = getInput.cpp createOutput.cpp main.cpp
OBJS = $(SRCS:.cpp=.o)

all: program.exe

program.exe: $(OBJS)
        $(CC) -o program.exe *.o $(CFLAGS) $(CFLAGS_SFML)

getInput.o: getInput.cpp
        $(CC) -c getInput.cpp $(CFLAGS)

createOutput.o: createOutput.cpp
        $(CC) -c createOutput.cpp $(CFLAGS)

main.o: main.cpp
        $(CC) -c main.cpp $(CFLAGS)

.PHONY : clean
clean:
        rm *.o
        @echo clean done

注意变量的定义OBJSSRCS

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM