由Mingw X86_64-W64-MINGW32编译的可执行文件在Windows上不起作用

发布于 2025-01-24 21:40:51 字数 1328 浏览 1 评论 0原文

我正在尝试在Linux上创建一个在Windows 64bit上创建可执行文件的作品。

我正在使用 mxe 在我的Ubuntu Server上交叉编译C文件。 然后将C文件编译为.exe文件后,将文件移至桌面(Windows 10 64bit)。

这就是我所做的。

  1. 安装了mingw-w64

    sudo apt-get安装mingw-w64

    sudo apt-get安装gcc-mingw-w64

  2. 我克隆了mxe git并设置了一些attrs。<<<<<<<<<<<<<<<<<<<<<<<<<<<< /p>

    git克隆https://github.com/mxe/mxe.git.git

    CD MXE

    echo mxe_targets = x86_64-w64-mingw32.static&gt; settings.mk

    制作CC

    echo'export path =“ $ path:$ home/mxe/mxe/usr/bin”'&gt;&gt; 〜/.bash_profile

  3. i创建了C文件进行测试。

      cat&lt;&lt;'eot'&gt; test.c
    #include&lt; stdio.h&gt;
    void main()
    {
        printf(“ Hello World \ n”);
    }
    eot
    
     
  4. 我将C文件编译为EXE文件。

    X86_64-W64-MINGW32-GCC -O test.exe test.c

最后,我可以获得Wingw编译的EXE文件,但是当我尝试在桌面Windows 10上打开此文件时,行不通。 当我打开此EXE文件时,只有很短的眨眼。

我尝试了X86_64-W64-MINGW32.STATIC-GCC来编译文件,但行不通。

x86_64-w64-mingw32.static-gcc: command not found

I am trying to create a executable file works on Windows 64bit from linux.

I am using MXE to cross compile c file on my ubuntu server.
And after I compile c file to .exe file, I move the file to my desktop(windows 10 64bit).

Here's what I did.

  1. installed mingw-w64

    sudo apt-get install mingw-w64

    sudo apt-get install gcc-mingw-w64

  2. I cloned the mxe git and set some attrs.

    git clone https://github.com/mxe/mxe.git

    cd mxe

    echo MXE_TARGETS=x86_64-w64-mingw32.static > settings.mk

    make cc

    echo 'export PATH="$PATH:$HOME/mxe/usr/bin"' >> ~/.bash_profile

  3. I created c file for test.

    cat<<'EOT' > test.c
    #include <stdio.h>
    void main()
    {
        printf("Hello World\n");
    }
    EOT
    
    
  4. I compiled c file to exe file.

    x86_64-w64-mingw32-gcc -o test.exe test.c

Finally I could get an exe file that I compiled by wingw, but when I try to open this file on my desktop Windows 10, it won't work.
There's only a short blink when I open this exe file.

I tried x86_64-w64-mingw32.static-gcc to compile the file, but won't work.

x86_64-w64-mingw32.static-gcc: command not found

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

落花浅忆 2025-01-31 21:40:51

如果您没有遇到错误,则可能有效。

您创建了一个控制台应用程序,因此它将打开一个控制台窗口,向其打印,并且当程序完成时,控制台窗口将关闭。那就是您看到的短眨眼。

打开命令提示符或PowerShell窗口,然后从那里运行test.exe。在控制台窗口上键入test.exe test.exe 的完整路径 test.exe ,然后按Enter。当程序退出时,控制台将保持打开状态,您将看到应用程序的输出。

If you don't get an error, it probably works.

You created a console application, so it will open a console window, print to it and when the program finishes the console window will close. That's the short blink you're seeing.

Open a Command Prompt or PowerShell window and run your test.exe from there. Type the full path to test.exe, or drag test.exe on the console window and press Enter. When the program exits, the console will remain open and you will see the output of your application.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文