go-sqlite3 icon indicating copy to clipboard operation
go-sqlite3 copied to clipboard

What is the proper way to build on ARM Windoes?

Open elgs opened this issue 2 years ago • 8 comments

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)

elgs avatar Mar 01 '23 15:03 elgs

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

rittneje avatar Mar 01 '23 23:03 rittneje

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.

elgs avatar Mar 02 '23 02:03 elgs

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 avatar Sep 18 '23 18:09 atheck

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 .

atheck avatar Sep 18 '23 19:09 atheck

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?

omushpapa avatar Nov 30 '23 19:11 omushpapa

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

karthik-karalgikar avatar Mar 12 '24 13:03 karthik-karalgikar

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

mattn avatar Mar 12 '24 14:03 mattn

down it and add bin to PATH, https://github.com/niXman/mingw-builds-binaries/releases

CC=aarch64-w64-mingw32-gcc GOOS=windows GOARCH=arm64 go build .

labulakalia avatar Nov 13 '24 06:11 labulakalia