Linking with MSVCRT.DLL versus the newer CRT DLLS

Started by GregL, August 31, 2008, 09:26:04 PM

Previous topic - Next topic

GregL

It seems that while Microsoft has been preaching to the developer community to move on to the new CRTs (MSVCR70.DLL, MSVCR80.DLL and MSVCR90.DLL), it has been updating the original CRT (MSVCRT.DLL) and compiling OS components and compiling their own products against it.

Interesting and useful blog post: Dynamically linking with MSVCRT.DLL using Visual C++ 2005


hutch--

Interesting read. Now I know why I write assembler and from time to time build a little C directly in C without a great gaggle of runtimes. The only thint I have seen the numbered vcrt DLLs perform is to break the backwards compatibility so the app will not run on an older version of Windows. I do see the old format mxvcrt.dll as a useful standard but I am very wary of the gaggle of new stuff around as it seems to be all over the place.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

GregL

The newer CRT DLLs are a pain in the rear. I'm not surprised Microsoft links to msvcrt.dll for their own applications. I keep a copy of Visual C++ 6.0 around just for this reason, and I use it quite a lot too.

Of course, using MASM and linking to msvcrt.dll (or not), you avoid all the problems too.   :U 



 

hutch--

I am lucky I don't have to do much with a C compiler these days but just about everything I need can be done with the VCTOOLKIT2003 with the then current SDK libraries added. I have cheated on occasions and used the masm32 version of MSVCRT.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

mitchi

This is true... I just tested a typical Console C program with Visual 2008
#include <stdio.h>

int main()
{
printf("hehe");
return 0;
}


7 KB release version, USES c:\windows\winsxs\x86_microsoft.vc90.crt_1fc8b3b9a1e18e3b_9.0.21022.8_none_bcb86ed6ac711f91\MSVCR90.DLL



mitchi

Wow, Wow, what a headache.

I just realized that all my console programs produced with Visual 2008 don't work on Windows XP SP3 !!!! Isn't that a recent Operating System !!
Why ? Because Windows XP doesn't have that DLL : MSVCR90.DLL
And it's just a hello world console program !

The error message you see when you're missing a DLL is this one

Quote---------------------------
C:\Documents and Settings\Administrator\Desktop\appConsoleTypique.exe
---------------------------
C:\Documents and Settings\Administrator\Desktop\appConsoleTypique.exe

This application has failed to start because the application configuration is incorrect. Reinstalling the application may fix this problem.

---------------------------
OK   
---------------------------


What are they THINKING !! Right now, writing your apps in assembler provides better compatibility  :green

ToutEnMasm

Hello,
I have also xp sp3,just donwload the redistributable 2008
Quote
C:\WINDOWS\WinSxS\x86_Microsoft.VC90.CRT_1fc8b3b9a1e18e3b_9.0.21022.8_x-ww_d08d0375\msvcr90.dll
C:\WINDOWS\WinSxS\x86_Microsoft.VC90.CRT_1fc8b3b9a1e18e3b_9.0.30729.1_x-ww_6f74963e\msvcr90.dll

TmX

mitchi,

Did you use the "Empty Project" template from the VS 2008 IDE?
Set the Runtime Library option to Multi-threaded (/MT)

No more msvcr90.dll, just kernel32.dll

GregL

QuoteSet the Runtime Library option to Multi-threaded (/MT)

Yes, linking statically avoids the problems too.  Microsoft recommends against that also, but hey, do what works for you.


Vortex

Hi mitchi,

Have a look at this thread to solve the VC installation and run-time library problems.

mitchi

I just want to link to MSVCRT.DLL with Visual Studio instead of the newest DLLS... Yesterday I put 2 hours trying to work this out using the WINDDK and finally gave up. They make it so difficult, it's a lot easier to just compile your project with VC6.

So far I know that there are many copies of Windows C runtime DLLS on Windows :
crtdll.dll (only C I think)
msvcrt.dll (C/C++, included on all systems)

Visual Studio 2005
msvcr80.dll
msvcp80.dll
msvcm80.dll

+3 other debug versions

Visual Studio 2008
msvcr90.dll
msvcp90.dll
msvcm90.dll
+3 debug versions



mitchi

Ok, I finally achieved what I wanted to have. I will post my results here in a second.
----

Ok so for those who use Visual Studio 2008, I have 2 projects here for you guys.
The first project links with CRTDLL.DLL without any runtime or commandline support. Naked programming just like with MASM. The .exe size is 2.5 k here. Of course all these settings are for the Release version.

The second project links directly with MSVCRT.DLL but with Vortex commandline support. The exe size is 2.5 k too.
I don't know if these projects will work with Visual 2008 Express because I don't use express. My school gives me a free Visual Studio (from MSDNAA) for my studies. And as I can see, Vortex's examples cover native code programming with Visual Studio Express perfectly...

http://mitchi.u7n.org/mitchiVS2008Projects.zip


Vortex

Hi mitchi,

I am doing my tests with VC 2008 Express SP1. You can install this software on a test machine ( or a virtual machine ) and then copy the necessary VC directories to your development computer. With this method, you can have a minimal VC installation without the IDE and keep clean the registry in your development machine.

Using Pelle's linker Polink.exe and merging the sections, I reduced the size of your application to 1024 bytes :

\masm32\bin\polink /SUBSYSTEM:CONSOLE /NODEFAULTLIB /LIBPATH:\masm32\lib /MERGE:.data=.text /MERGE:.rdata=.text Hello.obj crt0.lib kernel32.lib msvcrt.lib


[attachment deleted by admin]

BlackVortex

The hello world works fine for me, cool.

Disassembled it, pretty lean code. And no real dependencies.

mitchi

Awesome.. you merged the sections and you don't get DEP problems...
I tried to merge the sections with LINK.exe and got DEP problems  :red. I also saw that FILEALIGN:512 is the maximum alignment that Vista permits.

Talking about that ideal development environnement, very light for the registry. I agree that it's a good idea. We could find all the binaries that CL needs to work with + a folder full of includes and we would be good to go !
I tried to make it happen on my VM machine but I might be missing some critical DLLS to make CL work because I get this error when CL starts :

The system cannot execute the specified program.

It just might be these new Visual 2009 DLLS ! They follow me everywhere :D hahaha