code1.c /的.cpp
int a;
// ... and so on
code2.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
是否有任何全局變量的連接CC++之間的差異?
+1問很好 – Stuti 2011-06-16 11:30:18
您可以通過使用'static'或(最好)一個無名的命名空間避免C++的問題,但是這不是你的問題。我擔心C連接規則不夠熟悉(與C++相反)。 – Sven 2011-06-16 11:32:34
http://blogs.oracle.com/ali/entry/what_are_tentative_symbols – 2011-06-16 11:42:03