Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is runtime library a compiler option rather than a linker option?

I'm trying to build a C/C++ static library using visual studio 2005. Since the selection of the runtime library is a compile option, I am forced to build four variations of my library, one for each variation of the runtime library:

  • /MT - static runtime library
  • /MD - DLL runtime library
  • /MTd - debug static runtime library
  • /MDd - debug DLL runtime library

These are compiler options, not linker options. Coming from a Linux background, this seems strange. Do the different runtime libraries have different calling conventions or something? Why can't the different runtime libraries be resolved at link time, i.e. when I link the application which uses my static library?

like image 545
mch Avatar asked Feb 06 '09 20:02

mch


1 Answers

These options may add defines (__DLL and __DEBUG for example) that are used in the runtime library header files. One common thing to do is to add __declspec(dllimport) to function declarations when linked dynamically.

The compiler also seems to use these to assist the linker in linking to the correct libraries. This is explained in the MSDN.

like image 124
zdan Avatar answered Oct 22 '22 21:10

zdan