2008-10-05 86 views
13

我最近添加了-pedantic和-pedantic-errors給我的gcc編譯選項來幫助清理我的跨平臺代碼。一切都很好,直到它在外部包含的頭文件中發現錯誤。有沒有辦法關閉這個錯誤在外部頭檢查文件IE:如何忽略外部庫頭中的gcc編譯器迂迴錯誤?

保持檢查的文件包括如下:

#include "myheader.h" 

停止檢查包含文件是這樣的:

#include <externalheader.h> 

這裏是我得到的錯誤:

g++ -Wall -Wextra -Wno-long-long -Wno-unused-parameter -pedantic --pedantic-errors 
-O3 -D_FILE_OFFSET_BITS=64 -DMINGW -I"freetype/include" -I"jpeg" -I"lpng128" -I"zlib" 
-I"mysql/include" -I"ffmpeg/libswscale" -I"ffmpeg/libavformat" -I"ffmpeg/libavcodec" 
-I"ffmpeg/libavutil" -o omingwd/kguimovie.o -c kguimovie.cpp 

In file included from ffmpeg/libavutil/avutil.h:41, 
      from ffmpeg/libavcodec/avcodec.h:30, 
      from kguimovie.cpp:44: 
ffmpeg/libavutil/mathematics.h:32: error: comma at end of enumerator list 
In file included from ffmpeg/libavcodec/avcodec.h:30, 
      from kguimovie.cpp:44: 
ffmpeg/libavutil/avutil.h:110: error: comma at end of enumerator list 
In file included from kguimovie.cpp:44: 
ffmpeg/libavcodec/avcodec.h:277: error: comma at end of enumerator list 
ffmpeg/libavcodec/avcodec.h:303: error: comma at end of enumerator list 
ffmpeg/libavcodec/avcodec.h:334: error: comma at end of enumerator list 
ffmpeg/libavcodec/avcodec.h:345: error: comma at end of enumerator list 
ffmpeg/libavcodec/avcodec.h:2249: warning: `ImgReSampleContext' is deprecated 
(declared at ffmpeg/libavcodec/avcodec.h:2243) 
ffmpeg/libavcodec/avcodec.h:2259: warning: `ImgReSampleContext' is deprecated 
(declared at ffmpeg/libavcodec/avcodec.h:2243) 
In file included from kguimovie.cpp:45: 
ffmpeg/libavformat/avformat.h:262: error: comma at end of enumerator list 
In file included from ffmpeg/libavformat/rtsp.h:26, 
      from ffmpeg/libavformat/avformat.h:465, 
      from kguimovie.cpp:45: 
ffmpeg/libavformat/rtspcodes.h:38: error: comma at end of enumerator list 
In file included from ffmpeg/libavformat/avformat.h:465, 
      from kguimovie.cpp:45: 
ffmpeg/libavformat/rtsp.h:32: error: comma at end of enumerator list 
ffmpeg/libavformat/rtsp.h:69: error: comma at end of enumerator list 

回答

-3

你可以修復頭文件並將補丁提交給ffmpeg;與-pedantic兼容是一個有價值的目標,所以我相信他們會考慮它,特別是如果它只是刪除尾隨逗號等。

+10

這實際上並沒有回答這個問題。 – Nick 2009-03-19 17:00:52

+1

@KPexEA:請考慮重新分配接受的明顯更好的答案 - 幫助SO搜索結果和人類讀者發現答案。 – sehe 2011-11-03 23:29:27

0

想到一個想法(不要知道如果有這種的「開箱即用」參數):

編寫一個腳本,將你的編譯器的輸出,並刪除所有包含不在特定列表(標題標題行)。

這樣做不應該那麼辛苦。

29

對gcc使用-Wsystem-headers選項將打印與系統標題相關的警告消息,這些消息通常會被抑制。然而,你希望gcc基本上把這些文件當作系統頭文件,所以你可以嘗試傳遞「-isystem/usr/local/ffmpeg」(或者你安裝那個包的地方)來讓gcc忽略包含在文件中的錯誤這些目錄也是如此。

+0

太棒了!答案應該已被接受! – 2011-07-01 13:58:05

1

我不知道有什麼辦法告訴gcc停止發出這些警告。然而,你可以用類似llvm-gcc(或者僅僅是gcc)-pedantic 2的方式冒充地刪除第三方警告> & 1 | grep -v「/ usr /」

-2

你不能告訴GCC關於某些東西而不是其他人。你可能會認爲它是一個功能,儘管我懷疑它會被拒絕,理想上每個人都會變得迂腐。

您可以做的是自己修復頭文件,生成補丁程序,然後將該補丁程序應用於更高版本的頭文件(如果升級該庫)。

將修補程序提交給ffmpeg,希望他們能夠採用它,但是無論哪種方式,即使他們不接受它,也會覆蓋你。