How can I force MSVC++ to ignore CRT dependencies of a static library?

I don't know if it's possible to do this, but I would like the /NODEFAULTLIB to be applied to a static library project.

I have many application projects (A.exe, B.dll, C.dll) that use a common static library D.lib. This library has a lot of code and also has other .lib dependencies as well. One of them is the openssl library, which seems to have been built for win32 against the Release version of the CRT (i don't have the original project/sources).

So far, to avoid the mixing of the Release/Debug versions of CRT, I have to put the /NODEFAULTLIB:msvcrt.lib linker directive in all leaf projects (A.exe, B.dll). This works but I think it's not the ideal way of dealing with that issue. I tried to put this property in D.lib project, but it has no effect.

Is there a way to force msvc++ to ignore the msvcrt.lib dependency from the 3rd party library?


A .lib does not have any linker settings because you don't link it, you link to it. A .lib is just an archive of .obj files, sort of like an uncompressed .zip file - that's why you have to put the setting on all projects that link to it.

If you're using VS2005+ you could use property sheets so that you only have to put the setting in one place and then use that property sheet in all projects.

However, OpenSSL is just that - Open Source, so you should be able to get the source for the version you are using and build it again (and add it to your version control system of course). I thought OpenSSL could be built as a DLL or LIB, which would solve your problem as the DLL would not interfere with the linking of your code.

Failing that, you always have the option of slitting your functionality out into a separate DLL so that you only have issues with one project.

My understanding is that if library LIB in linked statically into a DLL, the DLL contains already all relevant code from LIB. Therefore, this coupling cannot be removed. This is just based on my understanding of statical linking, not on experiments.

To prevent your distributed static link library from depending on a specific MSVC runtime library you need to set this compiler option (in Visual Studio 2010 it looks like):

Configuration Properties -> C/C++ -> Advanced -> Omit Default Library Name = Yes (/ZI)

Now your users can link to your release built static lib from their debug build and not try to link to the incorrect runtime library causing problems, as well as linkers warnings.

Note that may cause link errors if your library actually depends on a specific runtime library or its behavior, and compatible components are not provided in some other way.

Need Your Help

Alphanumeric Shellcode Ensuring Jumps

assembly x86 shellcode

I'm trying to write some shellcode that will eventually be in the form of an English paragraph. This means that I'm mostly limited to instructions that have opcodes that evaluate to alphanumeric

call R ggplot with Rexcel

r vba ggplot2 rexcel

I click on a excel macro button which uses RExcel to execute an R script that generates a matrix