最简单的程序有g ++链接错误。随处搜索。
$ /usr/bin/g++ --version
g++ (GCC) 4.1.2 20080704 (Red Hat 4.1.2-55)
Copyright (C) 2006 Free Software Foundation, Inc.
$ cat /etc/redhat-release
CentOS release 5.11 (Final)
----- a.cpp -----
int main()
{
}
注意:我知道我不必指定-o选项,因为它将默认为a.out,所以这里发生了什么。我已经在其他机器上做过几十次了。
$ /usr/bin/g++ a.cpp
/usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../lib64/crti.o: In function `_init':
(.init+0x0): multiple definition of `_init'
/usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../lib64/crt1.o:(.init+0x0): first defined here
/usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../lib64/crti.o: In function `_fini':
(.fini+0x0): multiple definition of `_fini'
/usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../lib64/crt1.o:(.fini+0x0): first defined here
/usr/lib/gcc/x86_64-redhat-linux/4.1.2/crtbegin.o:(.rodata+0x0): multiple definition of `__dso_handle'
/usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../lib64/crt1.o:(.rodata+0x0): first defined here
/tmp/ccYgVWiH.o: In function `main':
a.cpp:(.text+0x0): multiple definition of `main'
/usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../lib64/crt1.o:(.text+0xa8): first defined here
/usr/bin/ld: Warning: size of symbol `main' changed from 18 in /usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../lib64/crt1.o to 11 in /tmp/ccYgVWiH.o
/usr/lib/gcc/x86_64-redhat-linux/4.1.2/crtend.o:(.dtors+0x0): multiple definition of `__DTOR_END__'
/usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../lib64/crt1.o:(.dtors+0x8): first defined here
/usr/bin/ld: warning: cannot find entry symbol _start; defaulting to 0000000000400430
注意:这适用于操作系统: 红帽企业Linux服务器版本5.1(Tikanga) 但不是在我的: CentOS版本5.11(最终版)
注意:这很好用但是我需要它没有-m32
/usr/bin/g++ -m32 a.cpp