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
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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.

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

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: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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

This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

627 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