Click to See Complete Forum and Search --> : __afxForceEXCLUDE


John E
April 16th, 2005, 12:50 PM
Never heard of it? Neither had I until today but I've had a bellyfull of it...! I'm trying to compile some source files for a project I've been given. The project neither uses nor needs MFC. However, for some reason, it insists on linking to a lib called uafxcw.lib, which I assume is something to do with AFX. If I link to this library I get the following linker errors:-

uafxcv.lib(appcore.obj) : error LNK2001: unresolved external symbol __wargv
uafxcv.lib(appcore.obj) : error LNK2001: unresolved external symbol __argc

However, if I try to exclude the library from my build, the linker throws up hundreds of errors about an unresolved external called __afxForceEXCLUDE. The only reference I can find to this is in AFX.h which contains a line saying.....

#pragma comment(linker, "/include:__afxForceEXCLUDE")

However, none of my source files is #including AFX.h. Somehow, the project (VC++ 6) must be set up to think that MFC is involved but I don't know how to turn this off. Has anyone come across this problem before?

JohnCz
April 18th, 2005, 10:04 AM
As comment on the top of #pragma explains that this symbol is used to force Nolib.obj to be included. Symbol is declared in NOLIB.CPP:

extern "C" { int __afxForceEXCLUDE; }

Including this module causes bunch of libraries to be excluded from linking if _AFXDLL (MFC extension dll) is not defined.

Uafxcw is a Unicode MFC extension Static Link Library (release build).

Your statement that project is not using nor needs MFC could be incorrect.
It takes only one library to reference something MFC specific to create MFC dependencies.

You may also have conflict with single/multi threading libraries.

What are your project settings in "General" tab of project setting dialog?

John E
April 18th, 2005, 10:23 AM
Thanks John,

I'm pretty certain that the project doesn't use MFC because it's cross-platform and supposedly platform independent. However, as you can probably tell, something somewhere is obviously including AFX.h.

I don't know if this makes sense to you - but since posting yesterday, I've discovered that the project builds just fine as long as I have precompiled headers enabled. If I turn them off, I get the above errors.

I must admit, it's all a mystery to me though.... :sick:

JohnCz
April 18th, 2005, 10:42 AM
You are welcome.
Off the top of my head, I really cannot think how enabling precompiled headers option could affect a build to that extend. I will have to give it some thoughts.
Besides without ability to work with a project directly, does not give me much room for drawing conclusion. All from this point on would be more or less just an educated guess.

Does project build when you choose "Rebuild All"?

John E
April 18th, 2005, 11:05 AM
Does project build when you choose "Rebuild All"?Believe it or not, no it doesn't...! It compiles okay but I end up with those linker errors. The only way to get it to build from start to finish is to enable precompiled headers.

At first, I thought there might be a difference between my headers and the ones that were originally used for the project (i.e. before it was given to me). But that's turned out not to be the case. If I delete the precompiled headers and rebuild them I get exactly the same linker errors. But everything works fine if PCH's are enabled.

Strange....