簡體   English   中英

gcc /g++ 生成 windows 可執行文件,僅在 msys2 bash 上創建 output,而不在其他終端上創建

[英]gcc /g++ produces windows executables that only create output on msys2 bash, not on other terminals

我有三台機器在 Windows 10 上運行 VSCode,並為 C++ 設置了 msys2 / mingw64 /gcc。

還安裝了 Microsoft Compiler cl.exe 和 Visual Studio 構建工具。

他們通過 Github 共享彼此的代碼。 在一台機器上,我在 Windows 上遇到了 MSYS2 GCC 編譯器系列(gcc /mingw64、gcc/ucrt64、clang64)的幾個問題。

可以說我有兩種類型的 cpp 文件, a.cppb.cpp (實際上是一大堆 .cpp 文件,它們始終以兩種方式中的一種方式表現)在我的“普通”PC 上,它們表現得很好 -我可以將它們加載到我的 VSCode 中,編譯並運行它們,它們會在命令行上生成一些簡單的 output。

我還可以在命令行上運行 gcc,例如gcc a.cpp -o a.exe ,然后調用生成的 a.exe,為我提供正確的 output。適用於帶有a.cppb.cpp

在我的“故障”電腦上,只有a.cpp類型的文件工作相同:我可以從 vsccode 或命令行編譯它們,從 cmd 終端,powershell 或從相應的 msys bash,然后執行它們,得到正確的output。

現在有b.cpp類型的文件

它們似乎像 VSCode 中的其他代碼一樣編譯得很好——沒有編譯器錯誤或類似的東西——但它們在執行時根本不會產生任何 output。 只是一個空行,然后它返回到提示符。

當我 go 到 cmd window 時,它變得更加奇怪:當我嘗試在 cmd 提示符下運行已編譯的 b.exe 時,一個消息框出現了消息

b.exe - Entry Point Not Found
The procedure entry point "_ZST28__throw_bad_array_new_lengthv" 
could not be located in dll "b.exe".

[OK]

(文本被翻譯成英語,因為它是德語 windows 版本)

因為它是使用 MigW64 環境編譯的,所以我嘗試使用 MingW64 bash,從那里運行編譯后的 b.exe,它工作:我確實得到了正確的 output。它也適用於 ucrt64 環境,但不適用於 clang64 環境。

當我 go 進入 clang64 bash 時,我可以將 b.cpp 編譯成 b-clang.exe,它可以工作並給出正確的 output。但是這個 b-clang exe 在 MingW64 bash 和 UCRT64 8831829834 in 856588 中都不起作用在最后一個中,在 cmd 中,它給了我另一個彈出錯誤消息框說

The execution of the code cannot proceed because libc++.dll was not found. 
Reinstalling the program may potentially fix the problem

[OK]

(文本已翻譯成英文)

我嘗試了全新安裝的 MSys2 環境,但沒有任何改變。

gcc --version on all machines (good ones and the faultyone) 給我

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 文件的簡短示例,它適用於所有 PC:

#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 類型的簡單文件 iof,它會在這台 PC 上做一些奇怪的事情:

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

已經是dll期了。 簡單的解決方案是將c:\msys64\mingw64\bin條目移動到路徑的開頭,作為第一個條目。 我確實遇到了很多問題,所以如果 somneone 遇到我描述的荒謬問題:請始終注意,當存在可能具有相同名稱的 .dll 文件時,您可能會遇到麻煩。

就我而言,我仍然必須仔細注意是否現在某些其他軟件無法正常工作,因為現在它會在需要的那些之前找到 msys2 dll。 (目前還沒有找到...)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM