1

我正在制作一个依赖于其他两个项目(由其他人编写)的新项目。当我开发我的代码时,我想使用 g++ 选项,-Wall -pedantic -Werror但是当我使用这些选项时,我会通过包含来自其他两个项目的文件来获得大量警告。

有什么办法可以忽略这两个项目的警告,但仍然看到我自己项目的警告?

4

1 回答 1

0

If you're compiling their source directly via a makefile, you can make optional CPPFLAGSwhich you can use for conditional compilation parameters. For example:

CPPFLAGS=-Wall -pedantic -Werror for your project and CPPFLAGS=-g for their project files (or something).

Take the following sample makefile. Assume you wrote factorial.cpp and hello.cpp and they wrote main.cpp:

CPPFLAGS+=-Wall -pedantic -Werror

all: hello

hello: main.o factorial.o hello.o
    g++ main.o factorial.o hello.o -o hello

main.o: main.cpp
    g++ -c main.cpp

factorial.o: factorial.cpp
    g++ -c $(CPPFLAGS) factorial.cpp

hello.o: hello.cpp
    g++ -c $(CPPFLAGS) hello.cpp

clean:
    rm -rf *o hello

Try something like that and get back to me.

于 2013-02-09T12:08:44.650 回答