删除某个目录的编译器警告

时间:2012-09-22 18:13:08

标签: c++ g++ compiler-warnings

我已启用-Wall-Wextra查看项目中的所有警告,但我还使用了'库'(我将文件夹的源代码复制/粘贴到文件夹中{我的项目的{1}}会弹出很多警告。代码附带一本书(OpenGL Super Bible 5),我用它来学习OpenGL。但是,我不希望看到此代码生成的所有警告,只看到libs文件夹中的警告。

有没有办法隐藏来自特定文件夹的警告?

我不会试图隐藏我的警告,我只想删除作者的警告,以便我可以集中精力修复自己的警告。

警告是

src

我担心如果禁用这些特定警告(./libs/src/GLTools.cpp:123:6: warning: unused parameter ‘szArgv’ [-Wunused-parameter] In file included from ./libs/src/GLBatch.cpp:36:0: ./libs/include/GLBatch.h: In constructor ‘GLBatch::GLBatch()’: ./libs/include/GLBatch.h:123:16: warning: ‘GLBatch::nNumTextureUnits’ will be initialized after [-Wreorder] ./libs/include/GLBatch.h:122:16: warning: ‘GLuint GLBatch::nNumVerts’ [-Wreorder] ./libs/src/GLBatch.cpp:55:1: warning: when initialized here [-Wreorder] In file included from ./libs/src/GLBatch.cpp:36:0: ./libs/include/GLBatch.h:131:17: warning: ‘GLBatch::pTexCoords’ will be initialized after [-Wreorder] ./libs/include/GLBatch.h:115:11: warning: ‘GLuint GLBatch::uiVertexArray’ [-Wreorder] ./libs/src/GLBatch.cpp:55:1: warning: when initialized here [-Wreorder] In file included from ./libs/src/GLBatch.cpp:36:0: ./libs/include/GLBatch.h:125:14: warning: ‘GLBatch::bBatchDone’ will be initialized after [-Wreorder] ./libs/include/GLBatch.h:121:16: warning: ‘GLuint GLBatch::nVertsBuilding’ [-Wreorder] ./libs/src/GLBatch.cpp:55:1: warning: when initialized here [-Wreorder] In file included from ./libs/src/GLBatch.cpp:36:0: ./libs/include/GLBatch.h:121:16: warning: ‘GLBatch::nVertsBuilding’ will be initialized after [-Wreorder] ./libs/include/GLBatch.h:118:12: warning: ‘GLuint* GLBatch::uiTextureCoordArray’ [-Wreorder] ./libs/src/GLBatch.cpp:55:1: warning: when initialized here [-Wreorder] ./libs/src/GLShaderManager.cpp:481:8: warning: unused parameter ‘szVertexProg’ [-Wunused-parameter] ./libs/src/GLShaderManager.cpp:481:8: warning: unused parameter ‘szFragProg’ [-Wunused-parameter] -Wunused-parameter),它们可能会在我自己的代码中发生,在这种情况下我会被告知。我是C ++的初学者,所以我希望得到编译器可以帮助我识别错误的所有帮助,或者我可能做的那些不好的做法。

3 个答案:

答案 0 :(得分:2)

您可以使用-isystem选项而不是-include作为包含库的包含文件的路径。然后,您可能只会在自己编译lib时看到警告。在源文件中包含这些文件不会导致警告

答案 1 :(得分:2)

你没有向我们展示你的makefile,但我认为它看起来像这样:

CC = gcc
CFLAGS = -Wall -Otherflags

MYOBJECTS = obj/foo.o obj/bar.o  # from sources in src/
LIBOBJECTS = obj/baz.o obj/quartz.o  # from sources in lib/
OBJECTS = $(MYOBJECTS) $(LIBOBJECTS)

executable: $(OBJECTS)
    ...

obj/%.o: %.cc
    $(CC) $(CFLAGS) $< -o $@

vpath %.cc src lib

如果是这样,只需添加target-specific variable

CFLAGS = -Otherflags

$(MYOBJECTS): CFLAGS += -Wall

答案 2 :(得分:-1)

AntoineG - 警告是有原因的。修复代码。