Reputation: 190
We can disable a compiler warning with
#pragma warning(disable:4966)
How can we disable a linker warning with a #pragma directive? Something like:
// Disable linker warning LNK4221
#pragma warning(disable:4221)
Upvotes: 4
Views: 1261
Reputation: 18411
Linker warning cannot be put in a source file, as source files (.CPP/.C/.H etc.) are for the consumption of the compiler and not for the linker. The compilation would produce object files out of one or more files (via one or more "translation units"). If you put #prama disable_linker_warning
in some source file - to which .OBJ file (part of linking) the linker setting should go?
Linker settings are global to the project - since .OBJ files are linked to produce final PE image, and linker warnings would be applied then. You can choose the linker warnings in the project settings page.
The preprocessor directives won't be saved and later propagated to the linker. It may lead to multiple path ambiguities (due to multiple translation units) and other complexities. Such linker feature may not be reliable.
Note that in VC++ when you select property of a single source file, you don't see any "Linker" setting.
Upvotes: 2
Reputation: 234635
You can't disable this warning with the current crop of MSVC toolsets.
Yes, warnings can be very useful indeed, but you are free to ignore this one in particular in many circumstances. Just make sure your situation is one of those circumstances, and move on. Are you sure, for example, that inclusion of the compilation unit that causes this warning is necessary?
Upvotes: 0