Warning - Microsoft updated the VC2005 CRT

Discussion area about developing or extending OGRE, adding plugins for it or building applications on it. No newbie questions please, use the Help forum for that.
User avatar
jacmoe
OGRE Retired Moderator
OGRE Retired Moderator
Posts: 20570
Joined: Thu Jan 22, 2004 10:13 am
Location: Denmark
x 179

Re: Warning - Microsoft updated the VC2005 CRT

Post by jacmoe »

You can actually turn on/off precompiled headers without touching any source files. :)

http://utilitypattern.wordpress.com/200 ... udio-2005/
http://codeblog.bsdninjas.co.uk/index.p ... -.NET.html
http://chadaustin.me/2009/05/unintrusiv ... aders-pch/

Yep - three links - because I haven't had the time to decide which article is the best. :P

But the trick is to use the build flag /FI (force includes), and a preprocessor define to toggle precompiled headers on/off.

Haven't tested this at home, but it sounds good :)
/* Less noise. More signal. */
Ogitor Scenebuilder - powered by Ogre, presented by Qt, fueled by Passion.
OgreAddons - the Ogre code suppository.
User avatar
Assaf Raman
OGRE Team Member
OGRE Team Member
Posts: 3092
Joined: Tue Apr 11, 2006 3:58 pm
Location: TLV, Israel
x 76

Re: Warning - Microsoft updated the VC2005 CRT

Post by Assaf Raman »

Assaf Raman wrote:Sometimes it is hard to add precompiled headers flag to existing projects, you get all sort of strange link errors (even before this include).
I found a way around this - just add an new h file with include to that file, a cpp file with include to the new h file, then set ONLY TO THAT FILE the precompiled headers with the PCH being the new h file. It works.
Do this only if you can't use the precompiled headers flag the normal way.
This doesn't seem to work is some cases - so - forget about it.
Watch out for my OGRE related tweets here.
User avatar
jacmoe
OGRE Retired Moderator
OGRE Retired Moderator
Posts: 20570
Joined: Thu Jan 22, 2004 10:13 am
Location: Denmark
x 179

Re: Warning - Microsoft updated the VC2005 CRT

Post by jacmoe »

Alright :)
The /FI flag forces all source files to include a certain file, like #include "pch.h", so no need to touch any sourcefiles with that approach.
But, I see what you mean. :wink:
/* Less noise. More signal. */
Ogitor Scenebuilder - powered by Ogre, presented by Qt, fueled by Passion.
OgreAddons - the Ogre code suppository.
User avatar
xavier
OGRE Retired Moderator
OGRE Retired Moderator
Posts: 9481
Joined: Fri Feb 18, 2005 2:03 am
Location: Dublin, CA, US
x 22

Re: Warning - Microsoft updated the VC2005 CRT

Post by xavier »

Assaf Raman wrote:Sometimes it is hard to add precompiled headers flag to existing projects, you get all sort of strange link errors (even before this include).
I found a way around this - just add an new h file with include to that file, a cpp file with include to the new h file, then set ONLY TO THAT FILE the precompiled headers with the PCH being the new h file. It works.
Do this only if you can't use the precompiled headers flag the normal way.
Generally you have your project set to "use" PCH, and have to set the properties for only one file (usually stdafx.cpp in the default MSVC project setups) to "create" the PCH. Otherwise, every file that compiles will try to create the PCH (and if you are doing parallel project file compilation, these will step all over one another).

Regarding your question from above, the steps you mentioned are the ones that didn't work, and it was on XP. It sounds like you found an undocumented file dependency too?
Do you need help? What have you tried?

Image

Angels can fly because they take themselves lightly.
User avatar
xadhoom
Minaton
Posts: 973
Joined: Fri Dec 28, 2007 4:35 pm
Location: Germany
x 1

Re: Warning - Microsoft updated the VC2005 CRT

Post by xadhoom »

I checked the demo project (which still doesn´t work) with the DependencyWalker:

He complains about two missing dll there (ofcourse all dlls shipped with the demo are in place):
IESHIMS.DLL
WER.DLL

I don´t know why he wants to open this files. Maybe this behaviour is related to my local compilation? Maybe I need to use my own dlls because they were used for compilation...
(XP SP3 VS2005)

xad
User avatar
Assaf Raman
OGRE Team Member
OGRE Team Member
Posts: 3092
Joined: Tue Apr 11, 2006 3:58 pm
Location: TLV, Israel
x 76

Re: Warning - Microsoft updated the VC2005 CRT

Post by Assaf Raman »

Do you use "Multi-threaded DLL (/MD)" as the runtime library?
Watch out for my OGRE related tweets here.
User avatar
xadhoom
Minaton
Posts: 973
Joined: Fri Dec 28, 2007 4:35 pm
Location: Germany
x 1

Re: Warning - Microsoft updated the VC2005 CRT

Post by xadhoom »

I just used the supplied demo project without any changes. Multithreaded is activated there...
User avatar
Assaf Raman
OGRE Team Member
OGRE Team Member
Posts: 3092
Joined: Tue Apr 11, 2006 3:58 pm
Location: TLV, Israel
x 76

Re: Warning - Microsoft updated the VC2005 CRT

Post by Assaf Raman »

I am using vs 2005 SP2.
Seems that you have to use precompiled header for project and all dependent projects (libs and such).
/FI worked for me. Good tip!
Watch out for my OGRE related tweets here.
User avatar
xadhoom
Minaton
Posts: 973
Joined: Fri Dec 28, 2007 4:35 pm
Location: Germany
x 1

Re: Warning - Microsoft updated the VC2005 CRT

Post by xadhoom »

As I said, I use the demo project. Precompiled headers are activated there...
Its just the configuration made by the guy who presented this approach. The only difference seems to be my workstation.

xad
User avatar
Assaf Raman
OGRE Team Member
OGRE Team Member
Posts: 3092
Joined: Tue Apr 11, 2006 3:58 pm
Location: TLV, Israel
x 76

Re: Warning - Microsoft updated the VC2005 CRT

Post by Assaf Raman »

You are right, but - this may be a vista\xp thing, if I compile on my XP - the exe doesn't work. If I compile with vista (I tried 2 computers), it does work.

When it works it will work on both xp and vista, when it doesn't work - it won't work on both.

Strange.
Watch out for my OGRE related tweets here.
User avatar
Assaf Raman
OGRE Team Member
OGRE Team Member
Posts: 3092
Joined: Tue Apr 11, 2006 3:58 pm
Location: TLV, Israel
x 76

Re: Warning - Microsoft updated the VC2005 CRT

Post by Assaf Raman »

If you upgrade to the CRT update this thread started with - it doesn't work anymore, before that update - it works.
Watch out for my OGRE related tweets here.
User avatar
Assaf Raman
OGRE Team Member
OGRE Team Member
Posts: 3092
Joined: Tue Apr 11, 2006 3:58 pm
Location: TLV, Israel
x 76

Re: Warning - Microsoft updated the VC2005 CRT

Post by Assaf Raman »

OK, now it works. If you updated to the latest CRT - the files dlls from the article don't work anymore. But if you get the latest files from "C:\Program Files\Microsoft Visual Studio 8\VC\redist\x86" (as he writes) and the modify the manifest files as he suggests – everything work.

Here are the steps to get this working:
  • 1. Download UseMSPrivateAssemblies.h from his article.
    2. Make your project compile with pre compiled headers (including all dependent lib and dll projects). You can use the /FI so you won't have to modify the source files for project that don't have pre compiled headers out of the box. Note – if you have c and cpp files in the same project – you needed a separate PCH file for them.
    3. Add #include "UseMSPrivateAssemblies.h" to all your PCH files.
    4. Copy all the files from C:\Program Files\Microsoft Visual Studio 8\VC\redist\x86 to same temp dir.
    5. Edit all the manifest files in that temp file – delete the < asmv2:hash > segment and publicKeyToken value.
    6. Copy the relevant manifest files and dll to the exe folder. (if you are not sure what you need or it doesn't work – copy them all and test by running, then deleting, then running once to see if it still runs.)
Tell me if it worked for you.

Note – this is a good way to solve the issue this thread started with – because if the CRT changes – your exe will stop to work on your computer until you will do steps 4-6 over.
Watch out for my OGRE related tweets here.
User avatar
Assaf Raman
OGRE Team Member
OGRE Team Member
Posts: 3092
Joined: Tue Apr 11, 2006 3:58 pm
Location: TLV, Israel
x 76

Re: Warning - Microsoft updated the VC2005 CRT

Post by Assaf Raman »

Can you post if my post helped or not? Does it still doesn't work for you?
Watch out for my OGRE related tweets here.
User avatar
xavier
OGRE Retired Moderator
OGRE Retired Moderator
Posts: 9481
Joined: Fri Feb 18, 2005 2:03 am
Location: Dublin, CA, US
x 22

Re: Warning - Microsoft updated the VC2005 CRT

Post by xavier »

If you are asking me, then you are referring to a problem I was dealing with some time last year -- the company no longer exists so neither does the problem, so it's not something I'm actively working on. ;)
Do you need help? What have you tried?

Image

Angels can fly because they take themselves lightly.
User avatar
xadhoom
Minaton
Posts: 973
Joined: Fri Dec 28, 2007 4:35 pm
Location: Germany
x 1

Re: Warning - Microsoft updated the VC2005 CRT

Post by xadhoom »

Sorry for the late reply Assaf!

It works for me now with your described way! :P
I´m currently just using the the sample project from the author but copying/modifying my own redist files did the trick.

Thanks for your investigation!
User avatar
Assaf Raman
OGRE Team Member
OGRE Team Member
Posts: 3092
Joined: Tue Apr 11, 2006 3:58 pm
Location: TLV, Israel
x 76

Re: Warning - Microsoft updated the VC2005 CRT

Post by Assaf Raman »

Great, I just wanted to make sure you guys are set. :D
Watch out for my OGRE related tweets here.
User avatar
xavier
OGRE Retired Moderator
OGRE Retired Moderator
Posts: 9481
Joined: Fri Feb 18, 2005 2:03 am
Location: Dublin, CA, US
x 22

Re: Warning - Microsoft updated the VC2005 CRT

Post by xavier »

Doesn't work for me XP SP2 --> XP SP2, VC9 release CRT DLLs. Depends.exe finds them just fine, but complains of side-by-side config issues, and trying to run the app causes the expected CRT-DLL-issue crash.
Do you need help? What have you tried?

Image

Angels can fly because they take themselves lightly.
User avatar
Assaf Raman
OGRE Team Member
OGRE Team Member
Posts: 3092
Joined: Tue Apr 11, 2006 3:58 pm
Location: TLV, Israel
x 76

Re: Warning - Microsoft updated the VC2005 CRT

Post by Assaf Raman »

Where did you take the CRT DLL files from?
Watch out for my OGRE related tweets here.
User avatar
xavier
OGRE Retired Moderator
OGRE Retired Moderator
Posts: 9481
Joined: Fri Feb 18, 2005 2:03 am
Location: Dublin, CA, US
x 22

Re: Warning - Microsoft updated the VC2005 CRT

Post by xavier »

From my VC9 install directory...not my first rodeo, ya know. ;)

C:\Program Files\Microsoft Visual Studio 9.0\VC\redist\x86\Microsoft.VC90.CRT
Do you need help? What have you tried?

Image

Angels can fly because they take themselves lightly.
User avatar
Assaf Raman
OGRE Team Member
OGRE Team Member
Posts: 3092
Joined: Tue Apr 11, 2006 3:58 pm
Location: TLV, Israel
x 76

Re: Warning - Microsoft updated the VC2005 CRT

Post by Assaf Raman »

OK, I will try to look it up this week.
Watch out for my OGRE related tweets here.
User avatar
xadhoom
Minaton
Posts: 973
Joined: Fri Dec 28, 2007 4:35 pm
Location: Germany
x 1

Re: Warning - Microsoft updated the VC2005 CRT

Post by xadhoom »

As a side note: I recently saw that Lightsmark 2008 also uses its own CRT files located in the Microsoft.VC90.CRT folder within the bin folder.
So its not an uncommon approach.

xad
User avatar
xavier
OGRE Retired Moderator
OGRE Retired Moderator
Posts: 9481
Joined: Fri Feb 18, 2005 2:03 am
Location: Dublin, CA, US
x 22

Re: Warning - Microsoft updated the VC2005 CRT

Post by xavier »

Yeah, not saying it's not possible ;) just that the method prescribed didn't work in my case. I'll try a simple one-project PCH solution as a sanity check first tho.
Do you need help? What have you tried?

Image

Angels can fly because they take themselves lightly.
User avatar
xavier
OGRE Retired Moderator
OGRE Retired Moderator
Posts: 9481
Joined: Fri Feb 18, 2005 2:03 am
Location: Dublin, CA, US
x 22

Re: Warning - Microsoft updated the VC2005 CRT

Post by xavier »

So, when I make a simple VC 2008 console Hello World exe project, and use the technique described, I get the following manifest generated for my executable:

Code: Select all

<?xml version='1.0' encoding='UTF-8' standalone='yes'?>
<assembly xmlns='urn:schemas-microsoft-com:asm.v1' manifestVersion='1.0'>
  <trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
    <security>
      <requestedPrivileges>
        <requestedExecutionLevel level='asInvoker' uiAccess='false' />
      </requestedPrivileges>
    </security>
  </trustInfo>
  <dependency>
    <dependentAssembly>
      <assemblyIdentity type='win32' name='Microsoft.VC90.CRT' version='9.0.21022.8' processorArchitecture='x86'  />
    </dependentAssembly>
  </dependency>
  <dependency>
    <dependentAssembly>
      <assemblyIdentity type='win32' name='Microsoft.VC90.MFC' version='9.0.21022.8' processorArchitecture='x86' />
    </dependentAssembly>
  </dependency>
  <dependency>
    <dependentAssembly>
      <assemblyIdentity type='win32' name='Microsoft.VC90.CRT' version='9.0.21022.8' processorArchitecture='x86' publicKeyToken='1fc8b3b9a1e18e3b' />
    </dependentAssembly>
  </dependency>
</assembly>
So the technique given with that header file isn't working to suppress VC9's generation of a dependency entry, and this causes errors noted in depends.exe:
crtmadness.PNG
Note that even though the dependency was found properly, when you try to execute the program, you get
crtmadness_error.PNG
It's not my top priorty atm -- I reverted back to my standard fix for this in a development environment, which is to make a dummy executable and package it up using the VS Deployment project type to make a poor-man's CRT .msi installer, for systems that don't have VS 2008 installed on them. And given that we're going to need an installer for any released product anyway, I'm not too worried about it atm. Just wanted to let you know that the technique isn't good for VC9 deployments. So whatever they used in that link, xad, isn't this technique. ;)

For the sake of completeness, here is the CRT manifest file (the one copied from the vc/redist directory, modified locally per Assaf):

Code: Select all

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
    <noInheritable></noInheritable>
    <assemblyIdentity type="win32" name="Microsoft.VC90.CRT" version="9.0.30729.1" processorArchitecture="x86"></assemblyIdentity>
    <file name="msvcr90.dll" hashalg="SHA1" hash="9785b1c493deb5b2134dc4aef3719cee207001bc">
	</file> 
	<file name="msvcp90.dll" hashalg="SHA1" hash="0f6bbf7fe4fb3fca2cb5b542eca1a1cad051f01c">
	</file> 
	<file name="msvcm90.dll" hashalg="SHA1" hash="7f3290ab2b7444c2b4a9b1fedfdb16466d7a21bb">
	</file>
</assembly>
I'll note that none of the modifications mentioned, Assaf, were actually needed, to make the executable recognize the local CRT files; that magic is done in that header file with the linker pragma. It's just that there doesn't seem to be enough magic in a VC9 environment...
You do not have the required permissions to view the files attached to this post.
Do you need help? What have you tried?

Image

Angels can fly because they take themselves lightly.
User avatar
xavier
OGRE Retired Moderator
OGRE Retired Moderator
Posts: 9481
Joined: Fri Feb 18, 2005 2:03 am
Location: Dublin, CA, US
x 22

Re: Warning - Microsoft updated the VC2005 CRT

Post by xavier »

Quick follow-up:

If I edit the intermediate manifest file to remove the VC-generated dependencies, and run the link command by hand at the command line (because "Project Only --> Link Only" generates the manifest again), then Depends.exe is happy
crtmadness_happy.PNG
but actually running the program isn't
crtmadness_unhappy.PNG
crtmadness_unhappy2.PNG
You do not have the required permissions to view the files attached to this post.
Do you need help? What have you tried?

Image

Angels can fly because they take themselves lightly.
User avatar
Assaf Raman
OGRE Team Member
OGRE Team Member
Posts: 3092
Joined: Tue Apr 11, 2006 3:58 pm
Location: TLV, Israel
x 76

Re: Warning - Microsoft updated the VC2005 CRT

Post by Assaf Raman »

God. Every visual studio version is harder.
Watch out for my OGRE related tweets here.