且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

用MinGW编译的C ++ HelloWorld程序会因“非法参数"而崩溃.

更新时间:2023-11-12 22:31:28

在查看了gdb的回溯之后,问题似乎出在C ++运行时 libstdc ++.dll 不兼容.

After looking at your gdb backtrace, the problem appears to be an incompatible C++ runtime libstdc++.dll.

如果您是在现有安装上安装MinGW,则可能会发生这种情况.发生这种情况的另一种方式是,如果某些需要 libstdc ++.dll 的第三方程序将其依赖项安装到您的 Windows \ SysWow64 中,因此可以在系统范围内找到它.问题当然在于, libstdc ++ 的不同版本在ABI级别上彼此不兼容.使用给定的Mingw g ++版本编译的程序需要加载特定Mingw安装随附的相应 libstdc ++.dll .

This could happen if you're installing MinGW over an existing install. Another way this could happen is if some other third party program needing libstdc++.dll installed its dependencies into your Windows\SysWow64 so it could be found system wide. The issue is of course, differing versions of the libstdc++ aren't compatible with each other at the ABI level. Programs compiled with a given Mingw g++ version needs to load the corresponding libstdc++.dll that came with that particular Mingw install.

打开一个新的cmd.exe提示符,并将路径环境 set 设置为当前 mingw \ bin 安装目录.例如,如果您的mingw安装位于 c:\ mingw32-4.7.2 :

Open a new cmd.exe prompt and set the Path environment to your current mingw\bin install directory. For example, if your mingw install is in c:\mingw32-4.7.2:

C:\>set path=C:\mingw32-4.7.2\bin

然后尝试再次运行helloworld.exe.如果它运行完成而没有崩溃,则可能是问题所在.在这种情况下,您应该从 windows \ syswow64 中删除libstdc ++.dll.

Then try running helloworld.exe again. If it runs to completion without crashing then that is likely the problem. In this case you should remove the libstdc++.dll from windows\syswow64.