[英]Cross compilation from windows 10 to raspberry pi CGO_ENABLED = 1
I wish to compile for a raspberry pi from my windows machine (much faster).我希望从我的 windows 机器上编译一个树莓派(快得多)。 Everything works if I use this command:
env GOOS=linux GOARCH=arm GOARM=5 go build src/*.go
如果我使用这个命令一切正常:
env GOOS=linux GOARCH=arm GOARM=5 go build src/*.go
However, I am using go-sqlite3
which apparently requires CGO_ENABLED = 1但是,我使用
go-sqlite3
显然需要 CGO_ENABLED = 1
Binary was compiled with 'CGO_ENABLED=0', go-sqlite3 requires cgo to work. This is a stub
When I change the compilation command to env GOOS=linux GOARCH=arm GOARM=5 CGO_ENABLED=1 go build src/*.go
I get an error on windows当我将编译命令更改为
env GOOS=linux GOARCH=arm GOARM=5 CGO_ENABLED=1 go build src/*.go
,我在 Z0F4137ED1502B505CAA286 上收到错误
$ 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
This looks like a simple fix, but I'm not very comfortable with cross compilation.这看起来像一个简单的修复,但我对交叉编译不太满意。 I cannot find much online.
我在网上找不到太多。
EDIT :编辑:
I moved my project around, and now I get the following error:我移动了我的项目,现在我收到以下错误:
$ 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'?*
I looked around online, and apparently one needs to specify the CC:我在网上看了一圈,显然需要指定CC:
$ 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%
So, I'm moving forwards to fixing the issue, but I am not there yet.所以,我正在着手解决这个问题,但我还没有。
I'll try finding how to install the gcc linux on windows and add it to PATH
.我将尝试查找如何在 windows 上安装 gcc linux 并将其添加到
PATH
。 However, if this is not the correct way of doing it.但是,如果这不是正确的做法。 I'm open to some help
我愿意寻求帮助
EDIT2编辑2
I donwloaded a tool chain from https://gnutoolchains.com/raspberry/ .我从https://gnutoolchains.com/raspberry/下载了一个工具链。 I copied the
arm-linux-gnueabihf-gcc.exe
to C:\Users\Me\go\bin
我将
arm-linux-gnueabihf-gcc.exe
到C:\Users\Me\go\bin
Now I get another error现在我得到另一个错误
$ 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
I'll keep posting my progress, but i'm sure the answer is dead simple.我会继续发布我的进展,但我相信答案很简单。 arf...
……
EDIT 3 Ok added the path to the system env and it is now found but... I now get some linker stuff issues编辑 3好的添加了系统环境的路径,现在找到了但是......我现在得到一些 linker 的东西问题
$ 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.
Ok, so through the edits I showed the work.好的,所以通过编辑我展示了这项工作。
To fix the initial problem cgo: exec C:\Program: exec: "C:\\Program": file does not exist
I moved the project in the GOPATH.要解决最初的问题
cgo: exec C:\Program: exec: "C:\\Program": file does not exist
我将项目移到了 GOPATH 中。
To fix the first edit cgo: exec arm-linux-gnueabi-gcc: exec: "arm-linux-gnueabi-gcc": executable file not found in %PATH%
I installed the toolchain from https://gnutoolchains.com/raspberry/ and made sure the C:\SysGCC\raspberry\bin
is added in both the user and system variables.要修复第一次编辑
cgo: exec arm-linux-gnueabi-gcc: exec: "arm-linux-gnueabi-gcc": executable file not found in %PATH%
我从https://gnutoolchains.com/raspberry安装了工具链/并确保在用户和系统变量中都添加了C:\SysGCC\raspberry\bin
。
To fix the second edit arm-linux-gnueabihf-gcc: fatal error: -fuse-linker-plugin, but liblto_plugin-0.dll not found
I installed https://sourceforge.net/projects/mingw/files/Installer/mingw-get-setup.exe/download and made sure that the following packets were installed要修复第二次编辑
arm-linux-gnueabihf-gcc: fatal error: -fuse-linker-plugin, but liblto_plugin-0.dll not found
我安装了https://sourceforge.net/projects/mingw/files/Installer/ming -get-setup.exe/download并确保安装了以下数据包
C:\MinGW\bin
was in both user and system variables.C:\MinGW\bin
在用户和系统变量中。 I then needed to restart all the terminals I worked with, and now the command compiles correctly然后我需要重新启动我使用的所有终端,现在命令可以正确编译
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.