Go Premium for a chance to win a PS4. Enter to Win


MSVC++ compiler warnings

Posted on 2004-09-17
Medium Priority
Last Modified: 2012-06-27
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.
Question by:lwinkenb
LVL 23

Accepted Solution

brettmjohnson earned 200 total points
ID: 12090192
> 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.

LVL 39

Assisted Solution

itsmeandnobodyelse earned 600 total points
ID: 12090320
>>> 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.


Assisted Solution

jimwasson earned 200 total points
ID: 12090334
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.
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

LVL 39

Expert Comment

ID: 12090461
>>> 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

Author Comment

ID: 12090676
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?
LVL 39

Assisted Solution

itsmeandnobodyelse earned 600 total points
ID: 12090684
/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

Featured Post

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.
Suggested Courses

916 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question