Visual Studio CRT - how to share a static lib used by clients with static and dynamic CRT?

403 Views Asked by At

If you have the following project structure:

 -Shared
 - Exe_Proj1
 - Exe_Proj2

Which use the CRT in the following ways:

-Shared (Dynamic CRT /MD)
  - Exe_Proj1 (Dynamic CRT /MD)
  - Exe_Proj2 (Static CRT /MT)

Then how can you share the "Shared" project with "Exe_Proj2"?

I thought about using /NODEFAULTLIB in shared but this won't change the CRT setting under the "code generation" project settings area.

1

There are 1 best solutions below

2
On

If Shared is a static library, you just can't do it. Make Exe_Proj2 use the dynamic CRT or die trying.

If Shared is a dynamic library, it should work, as long as you don't pass anything that needs the CRT services (any C++ standard library type, file handles, etc.) between the libraries, but in this case the linker shouldn't complain.