Solved

MSVC++ compiler warnings

Posted on 2004-09-17
6
854 Views
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.
0
Comment
Question by:lwinkenb
6 Comments
 
LVL 23

Accepted Solution

by:
brettmjohnson earned 50 total points
Comment Utility
> 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.

0
 
LVL 39

Assisted Solution

by:itsmeandnobodyelse
itsmeandnobodyelse earned 150 total points
Comment Utility
>>> 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.


0
 
LVL 7

Assisted Solution

by:jimwasson
jimwasson earned 50 total points
Comment Utility
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.
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 39

Expert Comment

by:itsmeandnobodyelse
Comment Utility
>>> 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
0
 
LVL 5

Author Comment

by:lwinkenb
Comment Utility
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?
0
 
LVL 39

Assisted Solution

by:itsmeandnobodyelse
itsmeandnobodyelse earned 150 total points
Comment Utility
/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
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

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…
Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
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.

743 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now