2012-09-21 73 views
0

我在學校有一個小組項目(3D FPS遊戲),我在C++中使用OpenAL和OGG Vorbis編程音頻。我們的編譯器設置爲警告我們已定義但未使用的變量,這是Vorbis的一個問題。當我編譯我們的應用程序,我得到這個:OGG 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定義,這不是我想要的。

請問誰能幫忙?提前致謝!

+2

好吧,只要忽略這些警告。或關閉它們。大多數情況下未使用的變量警告無用。 (我不得不承認,有時候他們是這樣,但事實並非如此。) – 2012-09-21 07:49:45

+0

這個特定的項目現在有超過16000行代碼,所以有時候不用的變量很有用。哦,我會和項目負責人談一談,只有在某些情況下才會開啓它。 –

回答

1

好的,我想我現在得到了解決方案。我們有標題複製到我們的應用程序目錄下的文件,所以我包括vorbisfile.h這樣:

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

當我改變了這個很行:

#include <vorbis/vorbisfile.h> 

的警告消失。不知道爲什麼。

+1

許多編譯器默認忽略來自系統標題的警告 – Christoph

+0

啊,我明白了,謝謝! –

2

個人而言,我想修改我的構建腳本過濾掉那些特定的警告,但如果你不玩遊戲,再到做...

您可以創建一個包裝headerfile,包括封裝文件,而不是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 ... 
    } 
} 
+0

感謝您的回答,我如何通過編輯構建腳本來過濾掉那些特定的警告? –

+0

如何過濾警告將取決於您的構建工具和操作系統。看起來你正在使用我不熟悉的CMake。 –