Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

What is the proper way to build on ARM Windoes? #1139

Open
elgs opened this issue Mar 1, 2023 · 7 comments
Open

What is the proper way to build on ARM Windoes? #1139

elgs opened this issue Mar 1, 2023 · 7 comments

Comments

@elgs
Copy link

elgs commented Mar 1, 2023

Issue description

I expect it to compile but it doesn't on Windows ARM.

Example code

package main

import (
	_ "github.com/mattn/go-sqlite3"
)

func main() {
  // ...
}

Error log

i> go build
# runtime/cgo
gcc_arm64.S: Assembler messages:
gcc_arm64.S:30: Error: no such instruction: `stp x29,x30,[sp,'
gcc_arm64.S:34: Error: too many memory references for `mov'
gcc_arm64.S:36: Error: no such instruction: `stp x19,x20,[sp,'
gcc_arm64.S:39: Error: no such instruction: `stp x21,x22,[sp,'
gcc_arm64.S:42: Error: no such instruction: `stp x23,x24,[sp,'
gcc_arm64.S:45: Error: no such instruction: `stp x25,x26,[sp,'
gcc_arm64.S:48: Error: no such instruction: `stp x27,x28,[sp,'
gcc_arm64.S:52: Error: too many memory references for `mov'
gcc_arm64.S:53: Error: too many memory references for `mov'
gcc_arm64.S:54: Error: too many memory references for `mov'
gcc_arm64.S:56: Error: no such instruction: `blr x20'
gcc_arm64.S:57: Error: no such instruction: `blr x19'
gcc_arm64.S:59: Error: no such instruction: `ldp x27,x28,[sp,'
gcc_arm64.S:62: Error: no such instruction: `ldp x25,x26,[sp,'
gcc_arm64.S:65: Error: no such instruction: `ldp x23,x24,[sp,'
gcc_arm64.S:68: Error: no such instruction: `ldp x21,x22,[sp,'
gcc_arm64.S:71: Error: no such instruction: `ldp x19,x20,[sp,'
gcc_arm64.S:74: Error: no such instruction: `ldp x29,x30,[sp],'

Configuration

Driver version (or git SHA):

github.com/mattn/go-sqlite3 v1.14.16 h1:yOQRA0RpS5PFz/oikGwBEqvAWhWg5ufRz4ETLjwpU1Y=
github.com/mattn/go-sqlite3 v1.14.16/go.mod h1:2eHXhiwb8IkHr+BDWZGa96P6+rkvnG63S2DGjv9HUNg=

Go version: run go version in your console

> go version
go version go1.20.1 windows/arm64

Server OS: E.g. Debian 8.1 (Jessie), Windows 10

Windows 11 Version 22H2 (OS Build 22621.1344)

@rittneje
Copy link
Collaborator

rittneje commented Mar 1, 2023

Sounds like you don't have a proper C compiler installed. What do go env, where gcc, and gcc --version say?

@elgs
Copy link
Author

elgs commented Mar 2, 2023

PS C:\Users\qianchen> go env
set GO111MODULE=
set GOARCH=arm64
set GOBIN=
set GOCACHE=C:\Users\qianchen\AppData\Local\go-build
set GOENV=C:\Users\qianchen\AppData\Roaming\go\env
set GOEXE=.exe
set GOEXPERIMENT=
set GOFLAGS=
set GOHOSTARCH=arm64
set GOHOSTOS=windows
set GOINSECURE=
set GOMODCACHE=C:\Users\qianchen\go\pkg\mod
set GONOPROXY=
set GONOSUMDB=
set GOOS=windows
set GOPATH=C:\Users\qianchen\go
set GOPRIVATE=
set GOPROXY=https://proxy.golang.org,direct
set GOROOT=C:\Users\qianchen\scoop\apps\go\current
set GOSUMDB=sum.golang.org
set GOTMPDIR=
set GOTOOLDIR=C:\Users\qianchen\scoop\apps\go\current\pkg\tool\windows_arm64
set GOVCS=
set GOVERSION=go1.20.1
set GCCGO=gccgo
set AR=ar
set CC=gcc
set CXX=g++
set CGO_ENABLED=1
set GOMOD=NUL
set GOWORK=
set CGO_CFLAGS=-O2 -g
set CGO_CPPFLAGS=
set CGO_CXXFLAGS=-O2 -g
set CGO_FFLAGS=-O2 -g
set CGO_LDFLAGS=-O2 -g
set PKG_CONFIG=pkg-config
set GOGCCFLAGS=-mthreads -Wl,--no-gc-sections -fmessage-length=0 -fdebug-prefix-map=C:\Users\qianchen\AppData\Local\Temp\go-build2489402497=/tmp/go-build -gno-record-gcc-switches
PS C:\Users\qianchen> where gcc
PS C:\Users\qianchen>
PS C:\Users\qianchen> which gcc
C:\Users\qianchen\scoop\apps\gcc\current\bin\gcc.EXE
PS C:\Users\qianchen>
PS C:\Users\qianchen> gcc --version
gcc.exe (GCC) 11.2.0
Copyright (C) 2021 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

@atheck
Copy link

atheck commented Sep 18, 2023

I have the same problem. I want to cross compile my go module using sqlite3 for a raspberry pi 3 (armv7). I'm calling go build like this:

GOOS=linux GOARCH=arm64 GOARM=7 CGO_ENABLED=1 go build .

Maybe I'm missing a parameter. Maybe that is not a problem of this sqlite3 package. Maybe gcc is not called correctly.

My gcc version is: "gcc (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0"

Does anybody have a hint?

@atheck
Copy link

atheck commented Sep 18, 2023

Ok, I found the answer in the docs and other issues.

I was missing the CC and CXX env variables and needed to install gcc-aarch64* packages.

sudo apt-get install gcc-aarch64-linux-gnu g++-aarch64-linux-gnu

My command was:

env CC=aarch64-linux-gnu-gcc CXX=aarch64-linux-gnu-g++ GOOS=linux GOARCH=arm64 GOARM=7 CGO_ENABLED=1 go build .

@omushpapa
Copy link

Ok, I found the answer in the docs and other issues.

I was missing the CC and CXX env variables and needed to install gcc-aarch64* packages.

sudo apt-get install gcc-aarch64-linux-gnu g++-aarch64-linux-gnu

My command was:

env CC=aarch64-linux-gnu-gcc CXX=aarch64-linux-gnu-g++ GOOS=linux GOARCH=arm64 GOARM=7 CGO_ENABLED=1 go build .

Also worked for me. Do you mind linking said issues?

@karthik-karalgikar
Copy link

Ok, I found the answer in the docs and other issues.

I was missing the CC and CXX env variables and needed to install gcc-aarch64* packages.

sudo apt-get install gcc-aarch64-linux-gnu g++-aarch64-linux-gnu

My command was:

env CC=aarch64-linux-gnu-gcc CXX=aarch64-linux-gnu-g++ GOOS=linux GOARCH=arm64 GOARM=7 CGO_ENABLED=1 go build .

when I try CGO_ENABLED = 1, I get the error -> " No such file or directory", but when I try CGO_ENABLED = 0, I do not get this error, but I do not get what I expected also. Can anyone tell me why this is happening?
I do not have any C files, in my folder now. So is that the reason as to why I am getting that error?
Thank you

@mattn
Copy link
Owner

mattn commented Mar 12, 2024

See https://github.com/mattn/go-sqlite3-crossbuild-example/blob/main/.github/workflows/release.yml

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants