C++ “多重”;“对……的多重定义”;在编译简单的Hello World时

C++ “多重”;“对……的多重定义”;在编译简单的Hello World时,c++,eclipse,mingw,C++,Eclipse,Mingw,我正在使用MinGW在eclipsec/C++Mars版中编译简单的helloworld 代码: 错误: multiple definitions of '__gcc_deregister_frame' multiple definitions of '__gcc_register_frame' multiple definitions of '_argc' multiple definitions of '_argv' multiple definitions of '_mingw32_ini

我正在使用MinGW在eclipsec/C++Mars版中编译简单的helloworld

代码:

错误:

multiple definitions of '__gcc_deregister_frame'
multiple definitions of '__gcc_register_frame'
multiple definitions of '_argc'
multiple definitions of '_argv'
multiple definitions of '_mingw32_init_mainargs'
multiple definitions of '_onexit'
multiple definitions of 'atexit'
multiple definitions of 'mainCRTStartup'
multiple definitions of 'WinMainCRTStartup;

默认情况下,MinGW将标准库链接为静态,libstdc++链接为共享,libgcc链接为共享(因为他的根来自Unix GCC)
-static
通常是
-static libgcc
的快捷方式,相反的是
-shared libgcc
(如果编译器默认静态链接,如TDM GCC,则很有用)

您的两个静态链接的组合是冗余的(请参阅),只需使用
static
。您只得到这几个符号,因为优化器丢弃了未使用的符号


主要的问题可能是,您没有编译多个对象文件并一次链接,而是使用标准库链接所有对象文件,最后将它们链接在一起。

摆脱
-static libgcc
,它是由链接器自动添加的。另外,对于C++,它应该是代码>静态LBSTDC++< /COD> FWIW,我无法复制它,使用(交叉编译)命令<代码>明文32-G++-O0-墙静态静态LBGCC Fo.CPP < /代码>;(尽管某些标志可能是冗余的,但它可以成功编译和链接)。您需要a)学习从命令行测试编译命令(不依赖任何IDE作为支撑),以及b)显示IDE代表您调用的命令的全文。这似乎不是一个MinGW问题;更可能是IDE/项目配置有问题。“没有工作”是人们能给出的最不有用的答案!怎么搞的?错误信息是否发生了变化,以及她看起来如何?您当前的命令行是什么(完全)?您使用了哪个MinGW项目?更具体地说,我不喜欢猜测。我和以前用的是同一个项目。错误消息根本没有改变。编译器标志如下
-I“H:\Eclipse\Workspace\Project”-O0-Wall
现在。多次指定同一个库不会导致多个定义错误;这些多个定义必须源于独立的对象文件(作为一个或多个源翻译单元中的重复定义,或者作为同一个对象文件对链接器的重复规范)。@KeithMarshall在很久以前,我确实遇到了GCC编译器无法识别多个相同链接的问题,但你是对的,这些天不应该这样。这就是为什么我要求提问者展示他的全部命令和错误信息。最后,我猜他错过了编译选项
-c
和链接,链接,链接(答案更新)。
-I"H:\Eclipse\Workspace\Project" -O0 -Wall -static -static-libgcc
multiple definitions of '__gcc_deregister_frame'
multiple definitions of '__gcc_register_frame'
multiple definitions of '_argc'
multiple definitions of '_argv'
multiple definitions of '_mingw32_init_mainargs'
multiple definitions of '_onexit'
multiple definitions of 'atexit'
multiple definitions of 'mainCRTStartup'
multiple definitions of 'WinMainCRTStartup;