We help IT Professionals succeed at work.

Why I sometimes need a double compile??

Dredwick
Dredwick asked
on
Medium Priority
510 Views
Last Modified: 2013-11-20
Sometimes when I'm compiling my program I get something like this:

--------------------Configuration: MTSMTPServiceParser - Win32 Debug--------------------
Compiling binary message file
MC: Compiling mtsmtpserviceparsermsg.mc
Compiling resources...
Compiling...
EmailParser.cpp
d:\program files\microsoft visual studio\vc98\include\crtdbg.h(536) : error C2833: 'operator DEBUG_NEW' is not a recognized operator or type
d:\program files\microsoft visual studio\vc98\include\crtdbg.h(536) : error C2059: syntax error : 'newline'
d:\program files\microsoft visual studio\vc98\mfc\include\afx.h(674) : error C2833: 'operator DEBUG_NEW' is not a recognized operator or type
d:\program files\microsoft visual studio\vc98\mfc\include\afx.h(674) : error C2059: syntax error : 'newline'
d:\program files\microsoft visual studio\vc98\mfc\include\afx.h(674) : error C2238: unexpected token(s) preceding ';'
d:\program files\microsoft visual studio\vc98\mfc\include\afx.h(675) : error C2833: 'operator DEBUG_NEW' is not a recognized operator or type
d:\program files\microsoft visual studio\vc98\mfc\include\afx.h(675) : error C2059: syntax error : 'newline'
d:\program files\microsoft visual studio\vc98\mfc\include\afx.h(675) : error C2238: unexpected token(s) preceding ';'
d:\program files\microsoft visual studio\vc98\mfc\include\afx.h(683) : error C2833: 'operator DEBUG_NEW' is not a recognized operator or type
d:\program files\microsoft visual studio\vc98\mfc\include\afx.h(683) : error C2059: syntax error : 'newline'
d:\program files\microsoft visual studio\vc98\mfc\include\afx.h(683) : error C2238: unexpected token(s) preceding ';'
d:\program files\microsoft visual studio\vc98\mfc\include\afx.h(1631) : error C2833: 'operator DEBUG_NEW' is not a recognized operator or type
d:\program files\microsoft visual studio\vc98\mfc\include\afx.h(1631) : error C2059: syntax error : 'newline'
d:\program files\microsoft visual studio\vc98\mfc\include\afxtls_.h(122) : error C2059: syntax error : 'string'
d:\program files\microsoft visual studio\vc98\mfc\include\afxtls_.h(123) : error C2091: function returns function
d:\program files\microsoft visual studio\vc98\mfc\include\afxtls_.h(123) : error C2802: static member 'operator new' has no formal parameters
d:\program files\microsoft visual studio\vc98\mfc\include\afxtls_.h(123) : error C2333: 'new' : error in function declaration; skipping function body
d:\program files\microsoft visual studio\vc98\mfc\include\afxtls_.h(131) : error C2059: syntax error : 'string'
d:\program files\microsoft visual studio\vc98\mfc\include\afxtls_.h(131) : error C2091: function returns function
d:\program files\microsoft visual studio\vc98\mfc\include\afxtls_.h(131) : error C2802: static member 'operator new' has no formal parameters
d:\program files\microsoft visual studio\vc98\mfc\include\afxtls_.h(135) : error C2059: syntax error : 'string'
d:\program files\microsoft visual studio\vc98\mfc\include\afxtls_.h(135) : error C2091: function returns function
d:\program files\microsoft visual studio\vc98\mfc\include\afxtls_.h(135) : error C2556: 'void *(__cdecl *__stdcall CNoTrackObject::operator new(void))(unsigned int,const char *,int)' : overloaded function differs only by return type from 'void *(__c
decl *__stdcall CNoTrackObject::operator new(void))(unsigned int)'
        d:\program files\microsoft visual studio\vc98\mfc\include\afxtls_.h(131) : see declaration of 'new'
d:\cprojects\mtsmtpserviceparser\emailparser.cpp(336) : fatal error C1903: unable to recover from previous error(s); stopping compilation
MTSMTPServiceParser.cpp
Skipping... (no relevant changes detected)
MTSMTPServiceParserDlg.cpp
NTEventLogSource.cpp
NTService.cpp
ParseThread.cpp
Plugins.cpp
PopMail.cpp
PopThread.cpp
SystemSettings.cpp
Error executing cl.exe.

MTSMTPServiceParser.exe - 24 error(s), 0 warning(s)

As soon as I compile WITHOUT CHANGING ANYTHING..It compiles, links and works correctly...This is kind of annoying..Anyone got any ideas?
Comment
Watch Question

CERTIFIED EXPERT
Author of the Year 2009
Commented:
I have seen that and I think it is related to a confusion with the precompiled header (pch) file.  I have found that a CLEAN and REBUILD fixes it.  You can also try tweaking the Precompiled Headers category in the C/C++ tab of the project settings (what are your current settings there?).  

Post the series of #include lines from the top of
    EmailParser.cpp

it *might* shed some light.

-- Dan
I used to get weird stuff like that when I was using Windows 95.
Even under simple projects; if I hit the run button too fast, the disk caching had not caught up with my keystrokes and so it would ask me if I wanted to compile before the run.
Once I moved to W2K, that stuff stopped.
What OS are you using?

Author

Commented:
That's another odd feature I wanted to ask about. I can do a save all, then compile, and after its done i hit  F5 for debug, then i get a popup saying such and such files are out of date and do i want to re-compile them. Lo and behold my final .exe which I JUST got done compiling is in the list. ARRRGH! I've never had this problem with ANY other projects :(

As far as my pre-compiled header selection. i have it set to automatic, but i don't have a header file listed in the text box...

THanks for the replies!
CERTIFIED EXPERT
Author of the Year 2009

Commented:
One of the files in your project might have a bad date.   Use the Wxplorer in detail mode and sort by date.  You will likely find that one source file has a date that is in the future.  Open that file, and save it to change its date to today.

And read the posts made by the experts and reply, providing the information requested.  Otherwise, why bother?

-- Dan

Author

Commented:
Thanks dan, I HAVE read the messages in their entirety. I will post the header file contents when that time becomes available to me. I will also look at the file dates, that seems to be a good start.

Thanks

Author

Commented:
// EmailParser.cpp : implementation file
//

#include "stdafx.h"
#include "EmailParser.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

Above is in the .CPP file.
--------------------------------
#if !defined(AFX_EMAILPARSER_H__F3D57C53_CEED_11D4_B052_00105AA276F8__INCLUDED_)
#define AFX_EMAILPARSER_H__F3D57C53_CEED_11D4_B052_00105AA276F8__INCLUDED_


#include "resource.h" //so IDD_PLUGINS is declared for .h at this level
#include "plugins.h"
#include "nteventlogsource.h"


#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
// EmailParser.h : header file
//
--------------------------
Here is the top of the .h file as specified.

Author

Commented:
Oddly enough, I also get this same problem with other projects in my solution. IE: Each has its own directory so no files are shared, and i have a total of 5 projects in the solution. All 5 use the same /debug /release directories for output 2 go to .exe files while the othe 3 goto /plugins/.dll files.
CERTIFIED EXPERT
Author of the Year 2009

Commented:
Did you check (all of) the file dates?

I don't think there is enough information to solve this because of the other .h files.  But one thing does jump out:

#include "resource.h" //so IDD_PLUGINS is declared for .h at this level

Did you add this line manually?  If so, try replacing it (for testing purposes) with:

#define IDD_PLUGINS 1234 // or whatever the real value is

There is something about resource.h that is handled specially by the VC++ IDE.  I have never seen it documented but consider this:  If you go in and add a new button to a dialog in the resource editor, you *know* that resource.h has changed, but the IDE does not force a rebuild of the entire project.  Based upon that and related observational evidence, I think that the VC++ build rules make some sort of exception related to that file.  Worth looking into, at least...

=-=-=-=-=-
Many (or all) of the errors are related to the redefintion of new to DEBUG_NEW.  The way this macro is implemented, it is expected that each source file have that in the CPP, after all of the other #includes.  For fun, you could try comment these out:

// #ifdef _DEBUG
// #define new DEBUG_NEW
// #undef THIS_FILE
// static char THIS_FILE[] = __FILE__;
// #endif

-- Dan

Author

Commented:
I went through my project with a fine toothed comb and cleaned things up. I seperated projects a little better directory wise and found some project settings which were inconsistent. After that, all the problems dissappeared! Apparently I managed to fudge things up:) Thanks Dan!