views:

362

answers:

3

I have an MFC C++ project compiler under Visual Studio 2008.

I'm adding a _AFX_NO_DEBUG_CRT in my stdafx.h before the #include to avoid all the debug new and deletes that MFC provides (I wish to provide my own for better cross platform compatibility).

However when I do this I get a stream of errors such as the following:

>c:\program files\microsoft visual studio 9.0\vc\atlmfc\include\afxtls_.h(62) : error C2059: syntax error : '__asm'
1>c:\program files\microsoft visual studio 9.0\vc\atlmfc\include\afxtls_.h(62) : error C2143: syntax error : missing ')' before '{'
1>c:\program files\microsoft visual studio 9.0\vc\atlmfc\include\afxtls_.h(62) : error C2143: syntax error : missing ')' before '{'
1>c:\program files\microsoft visual studio 9.0\vc\atlmfc\include\afxtls_.h(62) : error C2143: syntax error : missing ')' before '{'
1>c:\program files\microsoft visual studio 9.0\vc\atlmfc\include\afxtls_.h(62) : error C2143: syntax error : missing ';' before '{'
1>c:\program files\microsoft visual studio 9.0\vc\atlmfc\include\afxtls_.h(62) : warning C4091: '' : ignored on left of 'int' when no variable is declared
1>c:\program files\microsoft visual studio 9.0\vc\atlmfc\include\afxtls_.h(62) : error C2143: syntax error : missing ';' before 'constant'
1>c:\program files\microsoft visual studio 9.0\vc\atlmfc\include\afxtls_.h(62) : error C2143: syntax error : missing ';' before '}'
1>c:\program files\microsoft visual studio 9.0\vc\atlmfc\include\afxtls_.h(62) : error C2143: syntax error : missing ';' before ','
1>c:\program files\microsoft visual studio 9.0\vc\atlmfc\include\afxtls_.h(62) : error C2059: syntax error : ')'
1>c:\program files\microsoft visual studio 9.0\vc\atlmfc\include\afxtls_.h(62) : error C2059: syntax error : ')'
1>c:\program files\microsoft visual studio 9.0\vc\atlmfc\include\afxtls_.h(62) : error C2059: syntax error : ')'
1

I "think" it may have something to do with an __asm int 3 call but I cannot be sure. Has anyone had this problem before? If so, how did you fix it? Am i stuck with MFC's memory tracking? I really hope not because it will make my libraries a lot less cross platform :(

Any help would be hugely appreciated!

A: 

Try putting the #define in your project compile options rather than at the top of stdafx.h.

How can you expect to build a cross-platform library if you're using MFC? Avoiding the new and delete overloads won't make a difference.

Moreover, you'll never write allocation trackers as reliable and complete as those provided by MFC. YAGNI, focus on developing your actual application.

Aidan Ryan
My libraries are cross platform not the MFC portion.
Goz
Also worth noting that putting it into the project defines does not work either.
Goz
If your library is cross-platform why does it need an MFC #define?
Aidan Ryan
+1  A: 

I've come up with one method which involves using the /FORCE:MULTIPLE command line to force it to use mine instead of the MFC one. It all seems to be working quite nicely. I can, now, even track "mallocs" and "new"s performed by functions not owned by me :)

If anyone has any better solutions then please post them but for now this seems to solve my problem :)

Goz
Still doesn't answer the question of why your "cross-platform" library is linking MFC?
Aidan Ryan
The MFC application is linking my cross platform libraries ...
Goz
Would you mind explaining how you fixed your compilation issue?I'm getting exactly the same compile errors as you - did you remove your #define _AFX_NO_DEBUG_CRT?
Alan
i DID remove my define and seeing as all the problems related to that new definition of new the force multiple fixed the problem. Fat Elvis's post explains why such a define is bad (tm).
Goz
+2  A: 

I tried messing with the _AFX_NO_DAO_SUPPORT macro in the past and all it did was lead to endless crashes. I eventually came across this article:

PRB: Problems Occur When Defining _AFX_NO_XXX

It doesn't specifically list the one you are attempting to use, but it may still apply.

Fat Elvis
Cool definitely worth knowing but the define im trying to use does not appear to affect VTABLES. It appears to only be for a bunch of service functions rather than used in classes.
Goz