关于MinGW GCC编译C++程序动态链接到libgcc_s_dw2-1.dll的问题

当使用MinGW GCC 4.4.0编译C++程序时,可能会遇到动态链接到libgcc_s_dw2-1.dll导致的运行错误。该错误是由于在不同模块间抛出异常需要动态链接此库。为解决这个问题,可以使用-static-libgcc选项来禁止这种动态链接,或者在C语言中使用-shared-libgcc启用。在Eclipse中,可以通过Project->Properties -> C++ Build -> Settings -> MinGW C++ Linker -> Miscellaneous 添加"-static-libgcc"到Linker flags字段。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

如果你使用MinGW GCC 4.4.0默认选项编译C++程序,就会动态链接到libgcc_s_dw2-1.dll,编译后的执行文件运行时会出现错误:

 

其中的原因:

Dynamic linking with libgcc_s_dw2-1.dll is necessary to throw exceptions between different modules, such as between two DLLs or a DLL and an EXE. Consequently, it is the default for all languages other than C.

 

解决办法:

To disable this dynamic linking, use -static-libgcc. To enable this dynamic linking in C, use-shared-libgcc.

 

Eclipse中参数设置方法:
To add this flag in Eclipse, go to Project->Properties. Under "C++ Build", select "Settings". Under "MinGW C++ Linker", select "Miscellaneous". Add "-static-libgcc" to the "Linker flags" field. You may have to do this for your other build configurations and projects.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值