Search code examples
visual-c++runtimestdio

No library specified, yet printf gets linked into C++ program?


I have the following code:

#include <stdio.h>

int main()
{
    printf ("hello world\n");
    return 0;
}

Using MSVC++ 10.0 on Windows 7 x86, I compile it on the command line as follows:

cl.exe simple.cpp

This produces simple.exe (the compiler automatically calls the linker) and the executable displays the "hello world" message as expected. When I look into the executable w/ depends.exe, it shows kernel32.dll as the only dependency. When I dumpbin the contents of kernel32.dll library, there is no printf shown.

Does VC++ employ some sort of optimization so that printf is somehow included directly into the final executable? If so, how, and is it documented anywhere?


Solution

  • libc.lib is no longer used.

    The options for static or dynamic inclusion of C runtime library (CRT) on VC++ 10 are documented here. You can select the one you need/desire in Project Options.