• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 915
  • Last Modified:

MSVC++ compiler warnings

I'm getting the following warnings, and I cant figure out what they mean.

I get the following warning when trying to compile (I get the warning once for each .cpp file I have).
warning C4653: compiler option 'Optimizations (one or more of /Oawp[y])' inconsistent with precompiled header; current command-line option ignored

I then get the following warning from the linker:
warning LNK4089: all references to "WS2_32.dll" discarded by /OPT:REF

Thanks for your help.
4 Solutions
> warning C4653: compiler option 'Optimizations (one or more of /Oawp[y])'
> inconsistent with precompiled header; current command-line option ignored

Processing header files (*.h) can be a very time-consuming phase of program
compilation - especially when a large number of C and C++ files include the
same set of header files or a header file includes many others (like windows.h).
Modern compilers can "pre-compile" headers in advance (creating a *.p or
*.precomp file), significantly speeding up compilation of C code that includes
those header files.  Your warning states that the compiler options that were
used to precompile the headers are inconsistent with the compiler options you
specified to compile the C code.  In such cases, good compilers usually ignore
the precompiled header cache, compiling the C code (and its included headers)
with the compiler options you specified.  Microsoft (in its typical distain for the
programmer) instead disregards your wishes, ignoring the compiler options
you explicitly specified.

>>> Microsoft (in its typical distain for the programmer) instead disregards your wishes

I doubt, that the inconsistent compiler options were wilfully set by the asker. If i am right, these compiler warnings are useful.

If you want to use precompiled header files you must have the same #include statement (e. g. #include "stdafx.h") as the very first statement in all cpp files where the 'Use Precompiled Header' option is switched on. Look at Project Settings - C++ tab - Precompiled Headers: You can give a default for Debug and Release configuration regarding Precompiled Header Option (normally 'Use Precompiled Headers if you created the project by a wizard). However, if for any reason you don't want a single cpp file not using "precompiled headers", simply change the option to 'not using Precompiled Headers' for that single cpp file. Note, there is one (and only one) cpp file (normally stdafx.cpp) where the option is not 'use Precompiled Headers' but 'create Precompiled Header through ..'. That cpp file normally has only one #include statement, - the precomppiled header fie - and no implementation. If you build the project the first time (or after a clean) that cpp file is the first module to be compiled and the output is a .pch file, the precompiled header.

To eliminate your warnings, check all cpp files on their status regarding precompiled headers and make sure that the first include statement is equal to all cpp files that use or create the precompiled header file.

Regards, Alex

BTW, you must not use precompiled headers. I normally do switch them off as i had some significant problems when using them in a multi-developer project environment.

As mentioned before the precompiled header is re-used when possible. In MSVC this is a file with a "pch" extension. Here something has changed in the project -- something like files being added or deleted, compile options have changed, etc. Occasionally this happens when a lot of code is put into the header files rather than in the .cpp files. That code gets compiled into the pre-compiled header. The compiler is saying that the precompiled header was still used.

You can select a "rebuild all" to force rebuilding the precompiled header.

The linker warning is saying that it has removed all references to functions in WS2_32.dll as the /OPT:REF linker directive tells it to do. This could be because some function in the precompiled header referenced some WinSock functions but during later edit sessions any calls to that function was deleted so the WinSock functions weren't needed anymore.

I disagree with Alex. I use precompiled headers routinely with multiple developers and have no problems with them.
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

>>> i had some significant problems when using them in a multi-developer project environment.

The problem occurs if there are changes in a header file that is part of current .pch. The build process will recognize that if the header file is younger than the pch file. However, on a network environment and when using a configuration and versioning system that couldn't be guaranteed. If developer A made a rebuild of the project, thus generating a new pch file and *later* gets a 'new' header file (but having an older timestamp) from developer B, the pch file is no longer consistent and it's a good chance to get weird errors or crashes then.

Also the dependencies of a VC project easily can be spoiled by driive mappings, macros or opening the same project twice in Visual Studio. In all VC versions before 5.0 precompiled headers have been a real mess. It has improved now but it is far from being perfect.

However, if used with stdafx.h only there are no such problems, although i don't like them anyhow.

Regards, Alex
lwinkenbAuthor Commented:
Thanks for the comments guys.  The compiler warnings went away when I deleted all the temp files, and rebuilt everything.  Im still confused about the linker warning though.  What does /OPT:REF mean?
/OPT:REF tellls the linker to link only that library functions that have been called (and not all library modules of a given library). The opposite is /OPT:NOREF

Regards, Alex
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now