没有指定库,但 printf 被链接到 C++ 程序? [英] No library specified, yet printf gets linked into C++ program?
问题描述
我有以下代码:
#include <stdio.h>
int main()
{
printf ("hello world\n");
return 0;
}
在Windows 7 x86上使用MSVC++ 10.0,我在命令行编译如下:
Using MSVC++ 10.0 on Windows 7 x86, I compile it on the command line as follows:
cl.exe simple.cpp
这将生成 simple.exe(编译器自动调用链接器)并且可执行文件显示hello world".消息如预期.当我查看带有depends.exe 的可执行文件时,它显示kernel32.dll 是唯一的依赖项.当我转储 kernel32.dll 库的内容时,没有显示 printf.
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.
VC++ 是否采用了某种优化,以便 printf 以某种方式直接包含在最终的可执行文件中?如果是这样,它是如何记录的,是否记录在任何地方?
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?
推荐答案
libc.lib
不再使用.
在 VC++ 10 上静态或动态包含 C 运行时库 (CRT) 的选项已记录此处.您可以在项目选项中选择您需要/想要的.
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.
这篇关于没有指定库,但 printf 被链接到 C++ 程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!