Question

I have a group project at school (3D FPS game) and I program audio using OpenAL and OGG Vorbis in C++. Our compiler is set to warn us about defined, but not used variables, which turns out to be a problem with Vorbis. When I compile our application, I get this:

[  8%] Building CXX object CMakeFiles/fps.dir/src/audio/Sound.cpp.o
/home/berzeger/FPS/FPS/trunk/game/src/audio/../../include/vorbis/vorbisfile.h:82:21: warning: ‘OV_CALLBACKS_NOCLOSE’ defined but not used [-Wunused-variable]
/home/berzeger/FPS/FPS/trunk/game/src/audio/../../include/vorbis/vorbisfile.h:89:21: warning: ‘OV_CALLBACKS_STREAMONLY’ defined but not used [-Wunused-variable]
/home/berzeger/FPS/FPS/trunk/game/src/audio/../../include/vorbis/vorbisfile.h:96:21: warning: ‘OV_CALLBACKS_STREAMONLY_NOCLOSE’ defined but not used [-Wunused-variable]
[  9%] Building CXX object CMakeFiles/fps.dir/src/audio/MenuAudioController.cpp.o
/home/berzeger/FPS/FPS/trunk/game/src/audio/../../include/vorbis/vorbisfile.h:75:21: warning: ‘OV_CALLBACKS_DEFAULT’ defined but not used [-Wunused-variable]
/home/berzeger/FPS/FPS/trunk/game/src/audio/../../include/vorbis/vorbisfile.h:82:21: warning: ‘OV_CALLBACKS_NOCLOSE’ defined but not used [-Wunused-variable]
/home/berzeger/FPS/FPS/trunk/game/src/audio/../../include/vorbis/vorbisfile.h:89:21: warning: ‘OV_CALLBACKS_STREAMONLY’ defined but not used [-Wunused-variable]
/home/berzeger/FPS/FPS/trunk/game/src/audio/../../include/vorbis/vorbisfile.h:96:21: warning: ‘OV_CALLBACKS_STREAMONLY_NOCLOSE’ defined but not used [-Wunused-variable]
[ 10%] Building CXX object CMakeFiles/fps.dir/src/audio/GameAudioController.cpp.o
In file included from /home/berzeger/FPS/FPS/trunk/game/src/audio/GameAudioController.cpp:1:0:
/home/berzeger/FPS/FPS/trunk/game/src/audio/../../include/vorbis/vorbisfile.h:75:21: warning: ‘OV_CALLBACKS_DEFAULT’ defined but not used [-Wunused-variable]
/home/berzeger/FPS/FPS/trunk/game/src/audio/../../include/vorbis/vorbisfile.h:82:21: warning: ‘OV_CALLBACKS_NOCLOSE’ defined but not used [-Wunused-variable]
/home/berzeger/FPS/FPS/trunk/game/src/audio/../../include/vorbis/vorbisfile.h:89:21: warning: ‘OV_CALLBACKS_STREAMONLY’ defined but not used [-Wunused-variable]
/home/berzeger/FPS/FPS/trunk/game/src/audio/../../include/vorbis/vorbisfile.h:96:21: warning: ‘OV_CALLBACKS_STREAMONLY_NOCLOSE’ defined but not used [-Wunused-variable]
[ 11%] Building CXX object CMakeFiles/fps.dir/src/audio/AudioController.cpp.o
/home/berzeger/FPS/FPS/trunk/game/src/audio/../../include/vorbis/vorbisfile.h:75:21: warning: ‘OV_CALLBACKS_DEFAULT’ defined but not used [-Wunused-variable]
/home/berzeger/FPS/FPS/trunk/game/src/audio/../../include/vorbis/vorbisfile.h:82:21: warning: ‘OV_CALLBACKS_NOCLOSE’ defined but not used [-Wunused-variable]
/home/berzeger/FPS/FPS/trunk/game/src/audio/../../include/vorbis/vorbisfile.h:89:21: warning: ‘OV_CALLBACKS_STREAMONLY’ defined but not used [-Wunused-variable]
/home/berzeger/FPS/FPS/trunk/game/src/audio/../../include/vorbis/vorbisfile.h:96:21: warning: ‘OV_CALLBACKS_STREAMONLY_NOCLOSE’ defined but not used [-Wunused-variable]

And so on. You can see this is a mess in which important things get easily lost.

I don't seem to be able to find a way how to suppress vorbis' unused variables. I tried

#define OV_EXCLUDE_STATIC_CALLBACKS

but that disables all vorbis defines, which is not what I want.

Could anyone help, please? Thanks in advance!

Was it helpful?

Solution 2

OK, I think I got the solution now. We have header files copied into our app directory, so I was including vorbisfile.h this way:

#include "../../include/vorbis/vorbisfile.h"

When I changed this very line for:

#include <vorbis/vorbisfile.h>

The warnings disappeared. No idea why.

OTHER TIPS

Personally I'd modify my build script to filter out those particular warnings, but if you're not game to do that...

You could create a wrapper headerfile, include the wrapper file rather than the vorbis headers and use the problem variables in the wrapper header so that the warnings disappear. Assuming they're integer constants something like this should suffice.

//File: myvorbisfile.h
#include "vorbisfile.h"

// Dummy function in the anonymous namespace 
// to suppress the unused variables
namespace
{
   int hide_unused_variables()
   {
     return 0
      + OV_CALLBACKS_NOCLOSE
      + OV_CALLBACKS_DEFAULT
      ... Fill in the rest ...
    }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top