我在学校有一个小组项目(3D FPS游戏),我在C ++中使用OpenAL和OGG Vorbis编程音频。我们的编译器设置为警告我们有关已定义但未使用的变量,这些变量对Vorbis来说是一个问题。当我编译我们的应用程序时,我得到了这个:
[ 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]
等等。你可以看到这很糟糕,重要的事情很容易丢失。
我似乎无法找到如何抑制vorbis未使用变量的方法。我试过了
#define OV_EXCLUDE_STATIC_CALLBACKS
但禁用了所有vorbis定义,这不是我想要的。
有人可以帮忙吗?提前谢谢!
答案 0 :(得分:2)
就我个人而言,我会修改我的构建脚本来过滤掉那些特定的警告,但是如果你不是游戏来做那个......
您可以创建一个包装器头文件,包括包装器文件而不是vorbis头文件,并使用包装器头中的问题变量,以便警告消失。假设它们是整数常量,这样就足够了。
//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 ...
}
}
答案 1 :(得分:1)
好的,我想我现在得到了解决方案。我们将头文件复制到我们的app目录中,所以我用这种方式包含了vorbisfile.h:
#include "../../include/vorbis/vorbisfile.h"
当我改变这一行时:
#include <vorbis/vorbisfile.h>
警告消失了。不知道为什么。