Dynamically linking with MSVCRT.DLL using Visual C++ 2008 (instead of MSVCR90.DLL)

V

Viv

Hi all,

I wrote an application using Visual C++ 2008 that has to be as small
as possible. By using the /MD flag (Multi-threaded) I link dinamycally
with the MSVCR90.DLL which is not by default an all OSs. I would like
to link dinamically with the MSVCRT.DLL because then I won't need to
deploy the DLL as it's by default on every OS starting at least with
Win 2000.

1) I wrote a simple "hello world" application and I did the following
settings:
- Linker -> Input -> Ignore all default Libraries: Yes (/NODEFAULTLIB)
- then b/c I was getting linking errors I also did: Linker -> Command
Line -> Additional Options: msvcrt.lib
Now the app builds, but looking at the final exe with depends.exe I
see that it still depends on the: msvcr90.dll.
Can smbd tell me if this is a "normal" behaviour? I mean to still be
dependant on msvcr90.dll? And how could one actually get rid of the
msvcr90.dll?


2) I also read the article:
http://kobyk.wordpress.com/2007/07/20/dynamically-linking-with-msvcrtdll-using-visual-c-2005/
but this didn't work for me. Maybe I missed some steps? Can smbd that
actually succeded in doing that write the steps he/she did?

3) Related with the article mentioned above: How can the developers
that use WDK to build their products (eg drivers developers), to
actually run their products in debug mode if there is no where to be
found a msvcrtd.dll?


Thanks in advance,
Viv
 
W

Wilson, Phil

As you say, msvcrt.dll has been a standard built-in part of the OS since
Windows 2000, so you shouldn't need to do any static binding to that, and
anyway I'd be surprised if your binary has a direct dependency on
msvcrt.dll. Of course you still depend on msvcr90.dll because that's the CRT
associated with VC 9.0, not msvcrt.dll. You can't get rid of that unless
you can delete all of your CRT references, but I don't know if that's
actually possible.
 
J

Jonathan Wilson

What you ask is not possible, Visual C++ 2008 cannot use MSVCRT.dll as a c
runtime, only MSVCR90.dll
 
D

David Wilkinson

Viv said:
Hi all,

I wrote an application using Visual C++ 2008 that has to be as small
as possible. By using the /MD flag (Multi-threaded) I link dinamycally
with the MSVCR90.DLL which is not by default an all OSs. I would like
to link dinamically with the MSVCRT.DLL because then I won't need to
deploy the DLL as it's by default on every OS starting at least with
Win 2000.

1) I wrote a simple "hello world" application and I did the following
settings:
- Linker -> Input -> Ignore all default Libraries: Yes (/NODEFAULTLIB)
- then b/c I was getting linking errors I also did: Linker -> Command
Line -> Additional Options: msvcrt.lib
Now the app builds, but looking at the final exe with depends.exe I
see that it still depends on the: msvcr90.dll.
Can smbd tell me if this is a "normal" behaviour? I mean to still be
dependant on msvcr90.dll? And how could one actually get rid of the
msvcr90.dll?


2) I also read the article:
http://kobyk.wordpress.com/2007/07/20/dynamically-linking-with-msvcrtdll-using-visual-c-2005/
but this didn't work for me. Maybe I missed some steps? Can smbd that
actually succeded in doing that write the steps he/she did?

3) Related with the article mentioned above: How can the developers
that use WDK to build their products (eg drivers developers), to
actually run their products in debug mode if there is no where to be
found a msvcrtd.dll?

You should try static linking (/MT compiler option).

Project Properties->Configuration Properties->C/C++->Code Generation->Runtime
Library

This will most certainly work for your "hello world" application. Whether it can
be done for your actual application depends on what kind of architecture it has.
If you use DLL's, especially 3rd party DLL's, you probably won't be able to use
static linking.
 
G

Guest

Something like this. I don't know if I've used this
with 2008 compiler/libs; I know I have for 2005.
Some things you may have a problem with, like, off
the top of my head, _ftol2 but if you have a small
program and don't care for the rtl, this should do (but
you'll need to figure it out). Oh, I see I mention
ftol2. Posted only because, well, no one else did.
It's trivial - if it links. I think /QIfist or similar
would get rid of the need for _ftol2, but that's not
in (2008's) cl.exe anymore.

#if 1 // use 0 to always use vc7 rtl DLL (testing only)
#ifndef _DEBUG
#ifndef USE_VC8_RTL
// 21-Sep-2002: this is in the non-9x release (won't be released;
to get _ftol2)
#pragma comment(linker, "/NODEFAULTLIB:msvcrt80.lib")
//4-Jan-2003: not here anymore: #pragma comment(lib,
"/vs6/vc6/lib/msvcrt.lib")
///13-Feb-2007: no here: #pragma comment(lib,
"/apps/vs6/vc98/lib/msvcrt.lib")
#pragma comment(lib, "/prj_files/my_lib/vs6/msvcrt.lib")
#else
#ifdef SHOW_RTL_MSG // only show this when in 91_dsp.cpp
#pragma message("using VC8 RTL; USE_VC8_RTL defined")
#endif
#endif
#endif
#else
#pragma mac_MSG(" ********** USING VC8 RTL ************* testing")
#endif

The line wraps were unavoidable.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top