I wish to compile for a raspberry pi from my windows machine (much faster).
Everything works if I use this command:
env GOOS=linux GOARCH=arm GOARM=5 go build src/*.go
However, I am using go-sqlite3
which apparently requires 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
# 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:
$ 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
. However, if this is not the correct way of doing it. I'm open to some help
EDIT2
I donwloaded a tool chain from https://gnutoolchains.com/raspberry/. I copied the arm-linux-gnueabihf-gcc.exe
to 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
$ 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.
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.
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
C:\MinGW\bin
was in both user and system variables.I then needed to restart all the terminals I worked with, and now the command compiles correctly