我在 c++ 中的乘法声明有问题,但在 c 中没有。您可以查看代码以获取更多信息。
文件 main.c
#ifndef VAR
#define VAR
int var;
#endif
int main(){}
文件其他.c
#ifndef VAR
#define VAR
int var;
#endif
用 gcc 编译
gcc main.c other.c
>> success
用 g++ 编译
g++ main.c other.c
Output:
/tmp/ccbd0ACf.o:(.bss+0x0): multiple definition of `var'
/tmp/cc8dweC0.o:(.bss+0x0): first defined here
collect2: ld returned 1 exit status
我的 gcc 和 g++ 版本:
gcc --version
gcc (Ubuntu/Linaro 4.6.3-1ubuntu5) 4.6.3
Copyright (C) 2011 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
g++ --version
g++ (Ubuntu/Linaro 4.6.3-1ubuntu5) 4.6.3
Copyright (C) 2011 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.