MSVC++ compiler warnings

Posted on 2004-09-17
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 50 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 150 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 50 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.
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

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

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 150 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.

831 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