一些圖書館是越野車,並提出了很多警告,人們不希望在每次編譯時都得到這些警告,因爲它會淹沒有用的應用程序警告和錯誤。如何禁止幾個警告,但不是所有的警告都來自圖書館?
爲了抑制一種類型的警告或從圖書館所有這些包括,溶液是here從andrewrjones並回顧這裏爲了方便地使用(具有一個不同的例子,使其有用):
// Crypt++
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-variable"
#include "aes.h"
#include "modes.h"
#include "filters.h"
#include "base64.h"
#include "randpool.h"
#include "sha.h"
#pragma GCC diagnostic pop
作爲由andrewrjones解釋,-Wall
可用於抑制來自所包含庫的所有警告。
但是我怎樣才能抑制幾個警告,而不是所有的警告?
我已經測試包括他們的串像在這裏:
#pragma GCC diagnostic ignored "-Wunused-variable -Wunused-function"
通往以下錯誤:
warning: unknown option after '#pragma GCC diagnostic' kind [-Wpragmas]
或者在兩行:
#pragma GCC diagnostic ignored "-Wunused-variable"
#pragma GCC diagnostic ignored "-Wunused-function"
但第二一個被忽略。
gcc documentation on these diagnostic pragmas沒有幫助。我怎麼能這樣做?
編輯:這裏是一個MCVE:
#include <string>
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-variable"
#pragma GCC diagnostic ignored "-Wunused-function"
//#pragma GCC diagnostic ignored "-Wunused-variable,unused-function" // error
//#pragma GCC diagnostic ignored "-Wall" // does not work
#include "aes.h"
#include "modes.h"
#include "filters.h"
#include "base64.h"
#include "randpool.h"
#include "sha.h"
#pragma GCC diagnostic pop
using namespace std;
using namespace CryptoPP;
int main() {
byte k[32];
byte IV[CryptoPP::AES::BLOCKSIZE];
CBC_Mode<AES>::Decryption Decryptor(k, sizeof(k), IV);
string cipherText = "*****************";
string recoveredText;
StringSource(cipherText, true, new StreamTransformationFilter(Decryptor, new StringSink(recoveredText)));
}
建設有:
g++ -Wall -I/usr/include/crypto++ -lcrypto++ gdi.cpp
看來,它已經用於建設忽略ignored "-Wunused-function"
,和現在的作品!
在我的真實應用程序中,它總是被忽略。因此,在這一點上,我正在使用following solution作爲解決方法:-isystem/usr/include/crypto++
而不是-I/usr/include/crypto++
的編譯選項。它抑制來自crypto ++的所有警告。
如果「第二個被忽略」,我認爲你應該寫一個[mcve]並將其報告爲一個錯誤。 –
隨機猜測:「-Wunused-variable,unused-function」? –
另一個隨機猜測:在每個新的「忽略」前添加另一個「#pragma GCC診斷推送」? –