Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Question
Wednesday, July 5, 2006 2:47 PM
I have a MFC Dll. The issue seems to be precompiled headers. When I compile the project using the option "Create Precompiled Header," it works fine. However, when I later select "Use Precompiler Header," it doesn't link properly.
I simply get a...
error LNK2001: unresolved external symbol "int __cdecl _AfxInitManaged(void)" (?_AfxInitManaged@@YAHXZ)
Using Visual Studio 2005 Professional. What seems to be the problem? :|
All replies (11)
Wednesday, July 5, 2006 3:17 PM âś…Answered | 4 votes
Hold your horses there. The fact that precompiled headers is solution wide and project wide property doesn't mean that the setting should be the same for all source files. Right click and choose properties for each and every one of your .cpp files, set the stdafx.cpp one to create and all other to use.
Wednesday, July 5, 2006 3:07 PM | 2 votes
Your stdafx.cpp should have the setting switched to "Create Precompiled Header", while all other files which include stdafx.h should have "Use Precompiled header". Make sure this is the case, recompile the solution, and you should be set to go.
Wednesday, July 5, 2006 3:10 PM
That doesn't make sense. Precompiled headers is a global option, so switching it on will affect everything.
This project was created before and have always been using precompiled headers. However, I did recreate the project file and now the precompiled headers are giving me troubles. The project has been coded to take advantage of precompiled headers before.
Wednesday, July 5, 2006 6:19 PM
I never knew it was possible to do so.
I did so, but I recieve another error that is unfamiliar to me:
fatal error C1854: cannot overwrite information formed during creation of the precompiled header in object file: 'd:\w00t\visual studio 2005\projects\quicklinks\snapshot\1.0\release\optiontree.obj'
Wednesday, July 5, 2006 8:27 PM
Please make sure that you've got the settings for _all_ .cpp files, except stdafx.cpp, set to "Use Precompiled Header". Also, let stdafx.h be the first include in all the .cpp's which utilize the pch.
Upon verifying both of these steps; recompile the entire project. This should resolve the issue. You will not have to touch the precompiled header settings any more after doing this.
Wednesday, July 5, 2006 8:37 PM
All cpp files except stdafx are set to Use Precompiled Header. Stdafx is set to create precompiled header.
I may have a lead, though. Some of the source was placed in a subfolder and want to include stdafx.h. To fix this easily, I created another stdafx.h in that directory which included ..\stdafx.h. This error occours on the line that includes the stdafx.h in the sub directory. Is this the problem?
Only problem is that if I change it to ..\stdafx.h it complains it cannot find the precompiled header (since it has to be included in each cpp file).
Wednesday, July 5, 2006 8:41 PM
Why don't you just have the sub folder source files include "..\stdafx.h"?
Wednesday, July 5, 2006 8:45 PM
Because of this error:
fatal error C1010: unexpected end of file while looking for precompiled header. Did you forget to add '#include "stdafx.h"' to your source?
Wednesday, July 5, 2006 8:52 PM
Ah, right. Well #include "stdafx.h" should work even with the source file in a sub directory, and no stdafx.h in that particular sub dir. Delete the work around header/source file you created.
Wednesday, July 5, 2006 9:00 PM
After changing back and forcing a rebuild, it builds fine now :)
Friday, November 20, 2015 10:11 AM
Thanks! It worked for me!