1

If .lib files are for static linking and .dll files for dynamic linking why can I specify in C/C++ -> code generation -> runtime library options select multi threaded or multithreaded DLL when building an explicitly static library (ie when making a .lib) or when building a project and linking to a .lib library?

user3353819
  • 911
  • 2
  • 8
  • 21
  • 1
    This setting is for the runtime which is independent of the target that you are producing. What I mean by that is you can create a static .lib with a dynamic CRT or a dll with a static CRT and several other combinations.. – drescherjm Oct 27 '14 at 20:06
  • What, exactly, is CRT and when would I want to make it static or dynamic? I want to statically link my libraries, is that guaranteed if it is a .lib file either way? Runtime setting must match across all libraries right? – user3353819 Oct 27 '14 at 20:07

1 Answers1

2

Visual Studio allows you to specify how the CRT is going to be integrated into your project under C/C++->Code Generation->Runtime Library. This project setting controls how C/C++ routines used explicitly or internally (e.g. exception functions or STL routines) are going to be linked to your project.

You can create a static library which uses the CRT dynamically or statically by specifying the /MT or /MD flag during compilation.

Regarding advantages/disadvantages I'm linking this answer which features a pretty good list of points to keep in mind.

One last thing to notice: if your project is going to use multiple static libraries (including your .lib file), you should make sure that this CRT option matches during the linking phase otherwise you might encounter the (in)famous LNK4098 error.

Community
  • 1
  • 1
Marco A.
  • 43,032
  • 26
  • 132
  • 246