2

我启用-Wall-Wextra查看了我的项目中的所有警告,但我也在使用一个“库”(我将库的源代码复制/粘贴到libs我的项目的文件夹中),它会弹出很多警告。该代码附带一本书(OpenGL Super Bible 5),我正在使用它来学习OpenGL。但是我不想看到这段代码生成的所有警告,只看到我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-Wreorder),它们可能会发生在我自己的代码中,在这种情况下我会被告知。我是 C++ 的初学者,所以我想得到编译器可以给我的所有帮助来识别我的错误,或者我可能会做的事情是不好的做法。

4

3 回答 3

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

如果是这样,只需添加一个特定于目标的变量

CFLAGS = -Otherflags

$(MYOBJECTS): CFLAGS += -Wall
于 2012-09-22T18:50:26.870 回答
2

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

于 2012-09-22T18:23:55.490 回答
-1

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

于 2012-09-22T18:23:16.237 回答