[ubuntu 22.04]编译出 windows 程序的交叉编译环境
clq
浏览(573) -
2022-05-04 15:13:19 发表
编辑
关键字:
[ubuntu 22.04]编译出 windows 程序的交叉编译环境
转帖内容。确实可用,实用性未知。
----------------------------------------------------------------
https://blog.csdn.net/zuihaobushi/article/details/90167362
第一步:安装mingw32
sudo apt-get install mingw-w64
sudo apt-get install mingw-w64-tools
sudo apt-get install mingw-w64-i686-dev
sudo apt-get install mingw-w64-x86-64-dev
上面这些可能会有重复的地方,为了省劲,直接都安装了。
安装完之后就可以编译代码了
i686-w64-mingw32-gcc -o hello.exe hello.c
第二部:测试编译出来的程序
编译出来的exe文件可以copy到windows上测试,不过为了省劲,我想直接在linux上运行。这样就需要完整wine了。
sudo apt-get install wine-development
wine ~/hello.exe
hello world
第三部:编译64位程序
因为本人需要编译x64位程序,但测试发现程序为32位程序。
x86_64-w64-mingw32-gcc -o hello64.exe hello.c
第四部:在windows上使用pthread 库
pthread真的很好用,windows默认没有pthread库。
i686-w64-mingw32-gcc -o pthread_create.exe pthread_create.c -lpthread -D__WIN32
竟然发现直接编译过了,说明mingw32 已经把pthread库包含进去了。
跑到windows上面执行,报"libwinpthread-1.dll .......... not found"
我直接将/usr/i686-w64-mingw32/lib 文件夹下的 libwinpthread-1.dll文件复制到windows里面。发现可以运行了。
够简单,够粗暴吧?不过确实很爽
实际上我windows下面也下载了pthread库,可惜还是报找不到库,可能是gcc不是隐式加载吧。
使用cmake 构建交叉编译工程
正在研究,候补
https://www.jianshu.com/p/c50f0b60563b
https://blog.csdn.net/ubuntu64fan/article/details/8918808
https://blog.csdn.net/bytxl/article/details/50635788
关于MinGW编译程序出现缺少libgcc_s_dw2-1.dll问题
原来是链接时默认使用动态linking,对方的电脑无依赖的DLL模块。
于是我在链接后添加指令:
-static-libstdc++ -static-libgcc
参考资料:
https://www.systutorials.com/docs/linux/man/1-i686-w64-mingw32-gcc/
本帖子属于以下条目()
NEWBT官方QQ群1: 276678893
可求档连环画,漫画;询问文本处理大师等软件使用技巧;求档softhub软件下载及使用技巧.
但不可"开车",严禁国家敏感话题,不可求档涉及版权的文档软件.
验证问题说明申请入群原因即可.