简体   繁体   中英

Why do I get warning C4081 on this #pragma?

I am in the habit of removing all warning reported in my code. I just like a clean build if possible. I used

#pragma comment(lib,"some.lib");

I get this warning:

warning c4081: expected 'newline'; found ';'

I am uncertain why that would create a warning. Could I get help on removing it?

Its the semi-colon at the end of the line. Its not needed for #pragma .

edit: The warning says it all: Expected a newline at the end of the pragma, but found a semi-colon instead.

Tested with VS2008

You can selectively, and temporarily disable all warnings like this:

#pragma warning(push, 0)        

#include <boost/filesystem/operations.hpp>
#include <boost/filesystem/exception.hpp>
#include <boost/filesystem/convenience.hpp>
#include <boost/program_options.hpp>
#include <boost/foreach.hpp>
#include <boost/algorithm/string/replace.hpp>
#include <boost/filesystem/operations.hpp>
#include <boost/filesystem/exception.hpp>
#include <boost/bind.hpp>
#include <boost/iostreams/copy.hpp>
#include <boost/iostreams/filter/zlib.hpp>
#include <boost/iostreams/filtering_stream.hpp>
#include <boost/iostreams/device/back_inserter.hpp>

#pragma warning(pop)

Instead of 0 you can optionally pass in something like:

#pragma warning( push )
#pragma warning( disable : 4081)
#pragma warning( disable : 4706 )
#pragma warning( disable : 4707 )
// Some code
#pragma warning( pop ) 
#pragma warning(disable: 4081)

will disable the warning. but I can't repro the warning unless the syntax of the comment is wrong.

#pragma comment(lib "some.lib") 

gives me warning 4081 but

#pragma comment(lib, "some.lib") 

does not.

What is the text of your warning message?

Edit: I see now, forget adding a #pragma warning, just remove the ; from the end of the comment line. it's a syntax error.

您还没有提到编译器类型和版本,但我认为您需要在第二个参数中放置没有“.lib”的名称( 请参阅此处

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM