tags:

views:

809

answers:

6

I would like to deploy a very simple DLL with my C# application, but any DLL that I build in Visual Studio 2008 seems to have a dependency on "Microsoft.VC90.CRT". Is it possible to build a DLL using VS2008 without this dependency? How can I tell what is causing the dependency?

+1  A: 

Give this tool a shot: http://www.dependencywalker.com/. It will let you walk through your dependencies on a given exe or dll.

Will Bickford
It seems that just creating an empty DLL in VS2008 has this dependency as well. I haven't added any extra references or anything, just an empty project.
Jon Tackabury
+10  A: 

I'm not sure about the latest VC++ versions, but previously you could tell the linker to link with a static version of the MSVCRT runtime library instead of the dynamic (DLL) version. It's possible this option still exists.

Greg Hewgill
This is an interesting idea. It seems like MS recommends against doing this, but if it solves my issues...
Jon Tackabury
This worked like a champ - thanks.
Jon Tackabury
I disagree. You can run into all kinds of problems when you try to link static libraries within a library thats dynamic.
Tim Matthews
In theory, as long as you never pass a pointer in or out of the DLL interface and manipulate the memory allocation based on that pointer, there should be "no" issues. In practice of course....
jmucchiello
+6  A: 

According to this MSDN page, static libraries are still available. Go to project properties, configuration properties, C/C++, Code generation, Runtime Library.

Select Multithreaded Debug for the debug configuration, and Multithreaded for the release config. (Not sure if the names are all the same in VS2008, but should be "somewhere around there". Can update tomorrow with VS2008-specific differences)

Also, as wbic16 suggested, use dependency walker to identify other static dependencies.

peterchen
+3  A: 

If you're absolutely sure you don't have any dependencies on the C runtime, then you can avoid linking against it by enabling the "Ignore All Default Libraries" (/NODEFAULTLIB) flag under the Linker -> Input project options page. You may also have to disable basic runtime checks (set "Basic Runtime Checks" to Default under C/C++ -> Code Generation), and you might also have to remove the entry point (set "No Entry Point" to "Yes (/NOENTRY)" under Linker -> Advanced).

See also http://support.microsoft.com/kb/814472, it has some good information about building DLLs for Managed Extensions for C++.

Edit: Notice that running without C runtime also means you don't have easy memory allocation function like malloc() and new.

Adam Rosenfield
I think that the NODEFAULTLIB should only be used in those very rare circumstances when you can guarantee that the standard library is NOT being used. Otherwise, you are better off with linking the run time as static.
Jon Trauntvein
A: 

With a bit of work, libCTiny still works as a replacement for the default lib. This kind of library makes /NODEFAULTLIB usable.

To answer your second question, with the /VERBOSE linker switch the linker will tell you which symbols are taken from which library.

MSalters
A: 

Make sure your building every thing in release as often in debug, the dll gets linked with special debug dlls that are not normally shipped with windows and will cause dependency issues.

Lodle