【发布时间】:2021-07-24 13:25:54
【问题描述】:
我希望从我的 Windows 机器上编译一个树莓派(快得多)。
如果我使用此命令,一切正常:
env GOOS=linux GOARCH=arm GOARM=5 go build src/*.go
但是,我使用的是 go-sqlite3,这显然需要 CGO_ENABLED = 1
Binary was compiled with 'CGO_ENABLED=0', go-sqlite3 requires cgo to work. This is a stub
当我将编译命令更改为env GOOS=linux GOARCH=arm GOARM=5 CGO_ENABLED=1 go build src/*.go
我在 Windows 上遇到错误
$ env GOOS=linux GOARCH=arm GOARM=5 CGO_ENABLED=1 go build src/*.go
# runtime/cgo
cgo: exec C:\Program: exec: "C:\\Program": file does not exist
这看起来很简单,但我对交叉编译不太满意。我在网上找不到太多。
编辑:
我移动了我的项目,现在我收到以下错误:
$ env GOOS=linux GOARCH=arm GOARM=5 CGO_ENABLED=1 go build src/*
# runtime/cgo
gcc: error: unrecognized command line option '-marm'; did you mean '-mabm'?*
我在网上看了一圈,显然需要指定抄送:
$ env GOOS=linux GOARCH=arm GOARM=5 CGO_ENABLED=1 CC=arm-linux-gnueabi-gcc go build src/*
# runtime/cgo
cgo: exec arm-linux-gnueabi-gcc: exec: "arm-linux-gnueabi-gcc": executable file not found in %PATH%
所以,我正在着手解决这个问题,但我还没有解决。
我将尝试查找如何在 Windows 上安装 gcc linux 并将其添加到 PATH。但是,如果这不是正确的做法。我愿意寻求帮助
EDIT2
我从https://gnutoolchains.com/raspberry/ 下载了一个工具链。我将arm-linux-gnueabihf-gcc.exe 复制到C:\Users\Me\go\bin
现在我得到另一个错误
$ env GOOS=linux GOARCH=arm GOARM=5 CGO_ENABLED=1 CC=arm-linux-gnueabihf-gcc go build src/*
# runtime/cgo
arm-linux-gnueabihf-gcc: error: CreateProcess: No such file or directory
我会继续发布我的进度,但我相信答案很简单。啊……
编辑 3 好的,添加了系统环境的路径,现在找到了,但是...... 我现在遇到了一些链接器问题
$ env GOOS=linux GOARCH=arm GOARM=5 CGO_ENABLED=1 CC=arm-linux-gnueabihf-gcc go build src/*.go
# command-line-arguments
C:\Program Files\Go\pkg\tool\windows_amd64\link.exe: running arm-linux-gnueabihf-gcc failed: exit status 1
arm-linux-gnueabihf-gcc: fatal error: -fuse-linker-plugin, but liblto_plugin-0.dll not found
compilation terminated.
【问题讨论】:
-
当我这样做时得到
package src is not in GOROOT (C:\Program Files\Go\src\src),我猜我的配置不好 -
试试
go build ./src
标签: go cross-compiling cgo go-sqlite3