由Mingw X86_64-W64-MINGW32编译的可执行文件在Windows上不起作用
我正在尝试在Linux上创建一个在Windows 64bit上创建可执行文件的作品。
我正在使用 mxe 在我的Ubuntu Server上交叉编译C文件。 然后将C文件编译为.exe文件后,将文件移至桌面(Windows 10 64bit)。
这就是我所做的。
安装了mingw-w64
sudo apt-get安装mingw-w64
sudo apt-get安装gcc-mingw-w64
我克隆了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
i创建了C文件进行测试。
cat&lt;&lt;'eot'&gt; test.c #include&lt; stdio.h&gt; void main() { printf(“ Hello World \ n”); } eot
我将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.
installed mingw-w64
sudo apt-get install mingw-w64
sudo apt-get install gcc-mingw-w64
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
I created c file for test.
cat<<'EOT' > test.c #include <stdio.h> void main() { printf("Hello World\n"); } EOT
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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您没有遇到错误,则可能有效。
您创建了一个控制台应用程序,因此它将打开一个控制台窗口,向其打印,并且当程序完成时,控制台窗口将关闭。那就是您看到的短眨眼。
打开命令提示符或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 totest.exe
, or dragtest.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.