Why do I get warning C4081 on this #pragma? - c++

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.

You have not mentioned the compiler type and version, but I think you need to put the name without the ".lib" in second parameter (see here)

Related

gdiplus header causing problems [duplicate]

When I include gdiplus.h in a program that compiles well the first(there are many) error I get is:
c:\program files (x86)\microsoft sdks\windows\v7.0a\include\GdiplusImaging.h(77): error C2504: 'IUnknown' : base class undefined
Part of GdiplusImaging.h:
IImageBytes : public IUnknown <<< error!
{
public:
...
Why it is so? Where is this IUnknown class? And why it's not in GdiplusImaging.h?
My system is Windows7 x64. VisualStudio 2010.
Including part:
#include <windows.h>
#include <gdiplus.h>
using namespace Gdiplus;
#pragma comment (lib, "gdiplus.lib")
These are the standard includes for using GDI+:
#include <windows.h>
#include <objidl.h>
#include <gdiplus.h>
using namespace Gdiplus;
#pragma comment (lib,"Gdiplus.lib")
You should try to add windows.h and Unknwn.h header before gdiplus.h
#include <Unknwn.h>
#include <windows.h>
#include <gdiplus.h>

error LNK2005: void __cdecl mongo::uasserted(...) already defined

I get the error
mongoclient.lib(assert_util.obj) : error LNK2005: void __cdecl mongo::uasserted(...) already defined in someOwnFile.obj
at linking, along with mongo::msgasserted and mongo::msgasserted.
In someOwnFile.cpp, I have
#include <string>
#ifdef WIN32
// Needed for mongo BSON.
#pragma warning(push)
#pragma warning(disable: 4800)
#pragma warning(disable: 4244)
#pragma warning(disable: 4267)
#define _CRT_SECURE_NO_WARNINGS 1
#endif
#include <mongo/bson/bson.h>
#ifdef WIN32
#pragma warning(pop)
#endif
// ...
Why do I get the error? How can I fix it?
It seems that it has problems when including just this file.
Now I'm doing this:
#ifdef WIN32
// Mongo uses boost.filesystem. Include it here to force to link it in (via its pragma lib).
#include <boost/filesystem.hpp>
// Needed for mongo BSON.
#pragma warning(push)
#pragma warning(disable: 4800)
#pragma warning(disable: 4244)
#pragma warning(disable: 4267)
#define _CRT_SECURE_NO_WARNINGS 1
#endif
#include <mongo/client/dbclient.h>
#include <mongo/client/dbclient_rs.h>
#include <mongo/client/gridfs.h>
#ifdef WIN32
#pragma warning(pop)
#endif
And this works.

Using #pragma warning(push) and #pragma warning(pop) doesn't work as intended int his case

I'm compiling at a high warning level and while I have no warnings in my code, I get tens of thousands from included headers.So to disable them I do this:
#pragma warning(push)
#pragma warning(disable : 4365)
#include <D3Dcommon.h>
#include <d3d11.h>
#include <d3d11_1.h>
#pragma comment(lib, "d3d11.lib")
#include <d3dCompiler.h>
#include <D3D11Shader.h>
#pragma comment(lib, "D3DCompiler.lib")
#include <dxgiformat.h>
#include <dxgi.h>
#pragma warning(pop)
The problem is, I also have 5-6 disabled warnings in a header that is included everywhere in my code(for the entire project to see) and using the above pragmas for some reason enables them all back, giving me 150 thousand unwanted warnings all over the entire project.
The header with the 5-6 disabled warnings just lists them like this:(#### being different numbers)
#pragma warning(disable : ####)
#pragma warning(disable : ####)
#pragma warning(disable : ####)
#pragma warning(disable : ####)
......
I'm not using push or pop there, since I want them to be disabled everywhere.

#include <gdiplus.h> causes error

When I include gdiplus.h in a program that compiles well the first(there are many) error I get is:
c:\program files (x86)\microsoft sdks\windows\v7.0a\include\GdiplusImaging.h(77): error C2504: 'IUnknown' : base class undefined
Part of GdiplusImaging.h:
IImageBytes : public IUnknown <<< error!
{
public:
...
Why it is so? Where is this IUnknown class? And why it's not in GdiplusImaging.h?
My system is Windows7 x64. VisualStudio 2010.
Including part:
#include <windows.h>
#include <gdiplus.h>
using namespace Gdiplus;
#pragma comment (lib, "gdiplus.lib")
These are the standard includes for using GDI+:
#include <windows.h>
#include <objidl.h>
#include <gdiplus.h>
using namespace Gdiplus;
#pragma comment (lib,"Gdiplus.lib")
You should try to add windows.h and Unknwn.h header before gdiplus.h
#include <Unknwn.h>
#include <windows.h>
#include <gdiplus.h>

Error C2146: syntax error : missing ';' before identifier

The line in question is:
extern BOOL logged_in;
Here are my includes:
#define _WIN32_WINNT 0x0403 // Very important for critical sections.
#define WIN32_LEAN_AND_MEAN // Good to use.
#pragma optimize("gsy", on) // Global optimization, Short sequences, Frame pointers.
#pragma comment(linker, "/RELEASE") // Release code
#pragma comment(linker, "/opt:nowin98")
#pragma comment(linker, "/ALIGN:4096") // This will save you some size on the executable.
#pragma comment(linker, "/IGNORE:4108 ") // This is only here for when you use /ALIGN:4096.
#pragma comment(linker, "/ALIGN:4096") // This will save you some size on the executable.
//default headers
#include <windows.h>
#include <stdio.h>
#include <string.h>
#include <winsock2.h>
#include <time.h>
#include <stdlib.h>
#include <Winsvc.h>
#include <winuser.h>
#include <tlhelp32.h>
#include <tchar.h>
#include <shlobj.h>
#include <shlwapi.h>
#include <shellapi.h>
#include <commctrl.h>
#pragma comment(lib, "ws2_32.lib")
#pragma comment(lib, "urlmon.lib")
#pragma comment(lib, "shlwapi.lib")
#pragma comment(lib, "shell32.lib")
Any ideas?
I don't see the line in the above code, but "missing ‘;’ before identifier" means that you are missing a semicolon before that line.