c++ linker , how to link the iostream file?

一世执手 提交于 2019-12-23 20:14:52

问题


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?


回答1:


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++).




回答2:


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).



来源:https://stackoverflow.com/questions/9294749/c-linker-how-to-link-the-iostream-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!