例如:
代码1.c / .cpp
int a;
// ... and so on
代码2.c / .cpp
int a;
int main(void) {
return 0;
}
去编译:
$gcc code1.c code2.c # this is fine
$
$g++ code1.cpp code2.cpp # this is dead
/tmp/ccLY66HQ.o:(.bss+0x0): multiple definition of `a'
/tmp/ccnIOmPC.o:(.bss+0x0): first defined here
collect2: ld returned 1 exit status
C 和 C++ 之间是否有任何全局变量链接差异?