[英]c++ linker , how to link the iostream file?
I have a file named main.cpp
which includes iostream
. 我有一个名为
main.cpp
的文件,其中包含iostream
。
I compiled main.cpp
and it worked without errors, so my question is: I compiled main.cpp
and I did not link iostream
with main.cpp
, so how could this be possible? 我编译了
main.cpp
并且它没有错误,所以我的问题是:我编译了main.cpp
并且我没有将iostream
与main.cpp
链接,那么这怎么可能呢? Or did the compiler linked the iostream
automatically? 或者编译器是否自动链接了
iostream
?
The functions in iostream
are part of the C++ standard library, which you usually don't need to link explicitly. iostream
中的函数是C ++标准库的一部分,您通常不需要显式链接。
If you use a compiler that's not strictly a C++ compiler, you sometimes need to add something like -lstdc++
(at least, I do if I use gcc
rather than g++
). 如果您使用的编译器不是严格意义上的C ++编译器,您有时需要添加类似
-lstdc++
东西(至少,如果我使用gcc
而不是g++
,我会这样做)。
The iostream library is part of the “compiler”, in the largest sense of the word, and if you invoke the linker through the C++ compiler driver, ( g++
, cl
, etc.), it will be automatically included; 从最大的意义上讲,iostream库是“编译器”的一部分,如果通过C ++编译器驱动程序(
g++
, cl
等)调用链接器,它将自动包含在内; IDE's also generally arrange for it to be automatically included. IDE通常也会安排自动包含它。 If you invoke the linker directly (
ld
, link
, etc.), then you'll generally have to specify it explicitly. 如果直接调用链接器(
ld
, link
等),那么通常必须明确指定它。 The same thing is true if the compiler driver doesn't understand C++ (the case of gcc
). 如果编译器驱动程序不理解C ++(
gcc
的情况),情况也是如此。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.