简体   繁体   English

从 windows 10 交叉编译到树莓派 CGO_ENABLED = 1

[英]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.exeC:\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并确保安装了以下数据包

  • mingw-developer-toolkit mingw-开发者工具包
  • mingw32-base mingw32-base
  • mingw32-gcc-g++ mingw32-gcc-g++
  • msys-base I'm not sure all of them are necessary. msys-base 我不确定所有这些都是必要的。 I also made sure that 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.

相关问题 CGO:使用 cgo_enabled = 1 从 mac/windows 交叉编译到 linux amd64 - CGO: Cross compile from mac/windows to linux amd64 with cgo_enabled = 1 为什么CGO_ENABLED = 0的编译速度较慢? - Why is compiling with CGO_ENABLED=0 slower? 使用 go build CGO_ENABLED 交叉编译 - 警告:未找到 libudev.so.1 - Cross-compile using go build CGO_ENABLED - warning: libudev.so.1 not found CGO_ENABLED 如何影响动态与 static 链接? - How does CGO_ENABLED affect dynamic vs static linking? 必须使用 CGO_ENABLED 时会发生什么 - When using CGO_ENABLED is must and what happens 二进制是用 'CGO_ENABLED=0' 编译的,go-sqlite3 需要 cgo 才能工作。 这是一个存根 - Binary was compiled with 'CGO_ENABLED=0', go-sqlite3 requires cgo to work. This is a stub CGO_Enabled=1 需要在 Alpine Docker 容器中使用 SQLite 构建 Go 二进制文件 - CGO_Enabled=1 required building Go binary using SQLite in Alpine Docker container 为什么我的交叉编译的CGO二进制文件不会在Raspberry Pi(Raspbian)上运行? - Why won't my cross-compiled CGO binary run on the Raspberry Pi (Raspbian)? cgo (for darwin) 的交叉编译失败 - Cross-compilation of cgo (for darwin) fails 是否可以从 Go 应用程序检测 CGo 是否启用? - Is it possible from Go app to detect if CGo enabled?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM