Visual C++: CRT Source Code

The source code of the C Run-Time library (CRT) of Visual C++ can be found in the directory: C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\crt\src

Exploring the code, one sees that most of the C functions end up calling the Win32 API. The C++ library is licensed from Dinkumware. So, one can see the name of P. J. Plauger who created these files at their bottom. There are a few assembly files too (*.asm), which are mostly for memory and string operations.

About these ads

C Run-Time Libraries in Visual C++

Every Visual C++ project is linked with a C run-time library. This is called the CRT in Microsoft literature.

Depending on the support for multi-threading there are 2 kinds of CRT:

  • Single threaded CRT: This can only be statically linked. This CRT is used if one of the compiler options /ML or /MLd is specified. It would be linked with libc.lib or libcd.lib respectively for Release and Debug modes. The single-threaded CRT is completely deprecated and should not be used! :x
  • Multi-threaded CRT: This is the default kind of CRT and should be used always.

The type of linking (static or dynamic) and the configuration (Release or Debug), lead to 4 kinds of multi-threaded CRT:

  • Release mode and statically linked: Specified using the compiler option /MT. The library file used is libcmt.lib.
  • Debug mode and statically linked: Specified using the compiler option /MTd. The library file used is libcmtd.lib.
  • Release mode and dynamically linked: Specified using the compiler option /MD. The library file used is msvcrt.lib and the DLL file used at run-time is msvcr100.dll (depends on Visual C++ version).
  • Debug mode and dynamically linked: Specified using the compiler option /MDd. The library file used is msvcrtd.lib and the DLL file used at run-time is msvcr100d.dll (depends on Visual C++ version).

Reference: C Run-Time Libraries at MSDN.

BoostPro Binaries on 64-bit Computers

BoostPro Computing offers pre-compiled Boost library binaries for Windows here. This is the easiest way to install Boost on Windows, since compiling Boost source code can be quite painful. As of version 1.42.0, BoostPro only offers 32-bit binaries. It is important to note this since the BoostPro installer does not mention that it is 32-bit anywhere. Other 64-bit libraries and code compiled along with this Boost flavor will give strange linker errors like this:

Foobar.obj : error LNK2019: unresolved external symbol __imp____gmpq_clear referenced in function “public: __thiscall CGAL::Gmpq_rep::~Gmpq_rep(void)”

If you have to stick to BoostPro, then you might be forced to switch your other libraries or code to 32-bit mode.

Visual C++: Library Pragma

I find myself having to indicate the libraries I want linked in every time I do this. I found a neat (non-portable) trick in Visual Studio to do this.

Use the #pragma comment(lib, "libfile") [1] preprocessor directive to hint your compiler/linker to include these library files for linking. For example:

// Link cg libraries
#pragma comment(lib, "cg.lib")
#pragma comment(lib, "cggl.lib")

[1] msdn.microsoft.com/library/en-us/vclang/html/_predir_comment.asp

(via Adding MSDEV Libraries)