Windows下MSYS2 GCC编译程序仅在MSYS2 Bash有输出的问题
MSYS2 GCC编译C++程序执行异常问题
环境与问题概述
三台Windows 10机器均配置VSCode+MSYS2/mingw64/GCC开发C++,同时安装微软编译器cl.exe及Visual Studio构建工具,代码通过GitHub共享。其中一台机器的MSYS2各环境(gcc/mingw64、gcc/ucrt64、clang64)出现异常:存在两类cpp文件,正常机器上两类文件均可在VSCode或命令行编译运行并输出正常,但故障机器上表现分化。
故障机器具体表现
- a.cpp:可正常编译运行,在cmd、PowerShell、MSYS Bash中执行均输出正确结果;
- b.cpp:编译无报错,但执行异常:
- 在cmd/PowerShell中运行编译后的
b.exe,弹出错误框:b.exe - 找不到入口点 无法定位程序输入点"_ZST28__throw_bad_array_new_lengthv"于动态链接库b.exe中。 [确定]
- 在MingW64 Bash和ucrt64环境中运行
b.exe可正常输出,但clang64环境下无法正常运行; - 在clang64 Bash中编译生成的
b-clang.exe仅能在该环境运行,在其他环境及cmd中运行时弹出错误框:代码执行无法继续,因为找不到libc++.dll。 重新安装程序可能会解决此问题。 [确定]
- 在cmd/PowerShell中运行编译后的
已尝试操作与版本信息
- 已重装MSYS2环境,问题未解决;
- 所有机器的GCC版本一致:
gcc (Rev7, Built by MSYS2 project) 12.2.0 Copyright (C) 2022 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
示例代码
a.cpp(所有机器正常运行)
#include <iostream> using namespace std; int main ( void ) { string array [] = { "es", "wie", "geht", "Dir ?" }; string hilf = " "; int i = 0; int y = 0; while ( i < 3 ) { y= i+1; while ( y < 4 ) { if ( array [ i ] < array [ y ] ) { hilf = array [ i ]; array [ i ] = array [ y ]; array [ y ] = hilf; } y++; } // end while innen i++; } // end while aussen for ( string s : array ) cout << s << "\n "; }
b.cpp(故障机器上表现异常)
#include <iostream> #include <vector> #include <string> using namespace std; int main() { vector<string> msg {"\nHello", "C++", "World", "from", "VS Code", "and the C++ extension!\n"}; for (const string& word : msg) { cout << word << " "; } cout << endl; std::cout << "C++ language version : " << __cplusplus << std::endl; }
内容的提问来源于stack exchange,提问作者maddes8cht
相关产品推荐
相关产品推荐

