如何在Windows上使用CGO构建386 Arch的Lib?
我有一个Golang库,可以在Linux,MacOS和Windows上构建和效果很好。当我试图在AMD64 Windows VM上以386的形式构建它时,问题出在问题。我已经安装了最新的Golang SDK和MingW,这使AMD64构建工作正常,但不工作386:
PS > gcc -v
gcc.exe (MinGW-W64 x86_64-posix-seh, built by Brecht Sanders) 11.2.0
PS > go version
go version go1.18.3 windows/amd64
PS > $Env:GOOS = "windows"; $Env:GOARCH = "386"; $Env:CGO_ENABLED ="1"; go build -v -buildmode=c-shared -ldflags="-s -w" -gcflags="-l" -o xyz_amd64.dll xyz_win_dll.go
...
runtime/cgo
c:/programdata/chocolatey/lib/mingw/tools/install/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible c:/pro
gramdata/chocolatey/lib/mingw/tools/install/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/lib/libmingwthrd.a when searching for -lmingwt
hrd
...
<a lot of skipping incompatible messages here>
collect2.exe: error: ld returned 1 exit status
如何修复它? Afaik应该可以在同一盒子上为两个拱门建造。
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
CGO构建失败,我以这种方式解决它:首先,确保成功构建C代码。
通常,CGO交叉汇编需要C交叉汇编并进行交叉汇编。也许您可以添加SET
// #CGO CFLAGS:C_CROSSBUILD_PARAMETERS
。如您所见,这并不容易。这就是为什么交叉汇编不在窗口
Cgo build fail, I solve it by this way: firstly, ensure build C code successfully.
generally, cgo cross compilation require C cross compilation and Go cross compilation . maybe you can add set
// #cgo CFLAGS:C_CrossBuild_Parameters
.As you can see, it's not easy. It's why Cross compilation goes out the window
我在项目描述中找到了差异,然后切换到 https://www.mingw.mingw.mingw.mingw.mingw.mingw.mingw64.org/ 。它包含Arch 386和X64的Libs。现在,整个汇编对我来说很好。
I've found the diff in the project description and switched to https://www.mingw-w64.org/. It contains libs for both arch 386 and x64. Now across compilation works fine to me.