AntoineG
AntoineG

Reputation: 1247

Remove compiler warning for a certain directory

I enabled -Wall and -Wextra to see all the warning in my project, but I'm also using a 'library' (I copy/pasted the source code of the library in a folder libs of my project) which pops up a lot of warnings. The code comes with a book (OpenGL Super Bible 5), and I'm using it to learn OpenGL. However I don't want to see all the warnings generated by this code, only the warnings in my src folder.

Is there a way to hide warnings coming from a specific folder?

I do not try to hide MY warnings, I just want to remove the author's warning so that I can concentrate on fixing my own warnings.

The warnings are

./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]

I'm afraid if I disable those specific warnings ( -Wunused-parameter and -Wreorder ), they might happen in my own code in which case I would be told about it. I'm a beginner at C++ so I'd like to have all the help the compiler can give me to identify my errors, or things I might do that are bad practice.

Upvotes: 2

Views: 856

Answers (3)

Beta
Beta

Reputation: 99094

You haven't shown us your makefile, but I suppose it looks something like this:

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

If so, just add a target-specific variable:

CFLAGS = -Otherflags

$(MYOBJECTS): CFLAGS += -Wall

Upvotes: 2

Serge
Serge

Reputation: 6095

you may use -isystem option instead of -include for path that contains include files of your library. Then you probably will see warnings only when lib is compiled itself. inclusion of these files in your source files will not cause warnings

Upvotes: 2

Ed Heal
Ed Heal

Reputation: 59997

AntoineG - The warnings are for a reason. Fix the code.

Upvotes: -1

Related Questions