多个"...的多个定义";在编译简单的Hello World时 [英] Multiple "multiple definition of ..." while compiling simple Hello World

查看:128
本文介绍了多个"...的多个定义";在编译简单的Hello World时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用MinGW在Eclipse C/C ++ Mars Edition中编译简单的Hello World.

I was compiling the simple Hello World in Eclipse C/C++ Mars Edition using MinGW.

代码:

#include <iostream>

using namespace std;

int main(){
    cout << "Hello World!" << endl;
}

编译器标志:

-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;

推荐答案

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

MinGW links the standard libraries by default, libstdc++ as static, libgcc as shared (because of his roots from Unix GCC). -static usually is a shortcut for -static-libgcc, the opposite would be -shared-libgcc (useful if the compiler links statically by default, like TDM GCC).

两个静态链接的组合是多余的(请参阅 GCC链接选项),只需使用static.您只会得到这几个符号,因为优化器会丢弃不使用的符号.

Your combination of both static links is redundant (see GCC links options), just use static. You get only these few symbols, because the optimizer throws away what don't get used.

主要问题可能是,您不编译多个目标文件并仅链接一次,而是将所有文件与标准库链接在一起,最后将它们链接在一起.

The main problem may be, that you don't compile multiple object files and link once, instead you link all of them with the standard libraries and finally them together.

这篇关于多个"...的多个定义";在编译简单的Hello World时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆