cout在iostream中声明,但是在哪里定义? [英] cout is declared in iostream, but where it is defined?
问题描述
当我试图看到cout的定义,我登陆到iostream文件,其中它被声明为
When I try to see definition of cout, I land to iostream file where it is declared as,
extern _CRTDATA2 ostream cout;
那么它定义在哪里呢?因为extern只是声明而不是定义。
So where it is defined? Because extern is just declaration and not definition.
推荐答案
全局符号在与应用程序链接的运行时库中定义。例如,在 gcc
中,您传递编译器选项 -lstdc ++
,这将链接您的应用程序与 libstdc ++。a
库。这是所有这些符号的地方。
Global symbols are defined in a run-time library that you link with your applications. For example, in gcc
you pass the compiler option -lstdc++
that will link your application with the libstdc++.a
library. That is where all such symbols reside.
虽然,这是特定于你的编译器/运行时库版本,将有所不同。 Microsoft Visual C ++的行为可能不同,但思路是一样的:符号在C ++编译器提供的预编译库中。
Though, this is specific to your compiler/run-time library version and will vary. Microsoft Visual C++ may behave differently but the idea is the same: the symbols are inside the precompiled libraries that are delivered with your C++ compiler.
使用GNU,你可以输入: / p>
With GNU you can type:
nm -g libstdc++.a
查看库中的符号。输出可能看起来像这样(在很多其他行):
to see the symbols inside the library. The output may look like this (among lots of other lines):
ios_init.o:
U _ZSt3cin
globals_io.o:
0000000000000000 D _ZSt3cin
0000000000000000 D _ZSt4cerr
0000000000000000 D _ZSt4clog
0000000000000000 D _ZSt4cout
0000000000000000 D _ZSt4wcin
0000000000000000 D _ZSt5wcerr
0000000000000000 D _ZSt5wclog
0000000000000000 D _ZSt5wcout
这篇关于cout在iostream中声明,但是在哪里定义?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!