I have a file named main.cpp
which includes 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? Or did the compiler linked the iostream
automatically?
The functions in iostream
are part of the C++ standard library, which you usually don't need to link explicitly.
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++
).
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; IDE's also generally arrange for it to be automatically included. If you invoke the linker directly ( ld
, link
, etc.), then you'll generally have to specify it explicitly. The same thing is true if the compiler driver doesn't understand C++ (the case of gcc
).
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.