【问题标题】:OGG Vorbis: Defined, but not used - how to suppress?OGG Vorbis:已定义,但未使用 - 如何抑制?
【发布时间】:2012-09-13 15:02:08
【问题描述】:

我在学校有一个小组项目(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 定义,这不是我想要的。

有人可以帮忙吗?提前致谢!

【问题讨论】:

  • 好吧,忽略这些警告。或者关闭它们。在大多数情况下,未使用的变量警告没有用处。 (我不得不承认,有时确实如此,但事实并非如此。)
  • 这个特定的项目现在有超过 16000 行代码,所以有时未使用的变量很有用。哦,好吧,我会和项目负责人谈谈只在某些情况下打开它。

标签: c++ c openal ogg vorbis


【解决方案1】:

我个人会修改我的构建脚本以过滤掉那些特定的警告,但如果你不喜欢这样做......

您可以创建一个包装头文件,包含包装文件而不是 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 ...
    }
}

【讨论】:

  • 感谢您的回答,如何通过编辑构建脚本仅过滤掉那些特定的警告?
  • 如何过滤掉警告取决于您的构建工具和操作系统。看起来您正在使用我不熟悉的 CMake。
【解决方案2】:

好的,我想我现在找到了解决方案。我们将头文件复制到我们的应用程序目录中,所以我以这种方式包含 vorbisfile.h:

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

当我将这一行更改为:

#include <vorbis/vorbisfile.h>

警告消失了。不知道为什么。

【讨论】:

  • 许多编译器默认忽略来自系统头文件的警告
猜你喜欢
  • 1970-01-01
  • 2014-12-28
  • 2016-02-25
  • 2015-07-13
  • 2011-11-11
  • 2011-06-12
  • 2011-05-19
  • 2013-12-14
  • 2011-02-08
相关资源
最近更新 更多