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

go/build: running gcc failed: exit status 1 when I try to compile simple hello world program to android/arm #45280

Open
m-abdalrahman opened this issue Mar 29, 2021 · 7 comments

Comments

@m-abdalrahman
Copy link

@m-abdalrahman m-abdalrahman commented Mar 29, 2021

What version of Go are you using (go version)?

go version go1.16.2 linux/amd64

Does this issue reproduce with the latest release?

Yes

What operating system and processor architecture are you using (go env)?

go env Output
GO111MODULE=""
GOARCH="amd64"
GOBIN="/media/user/sda7/golang/go-lib/bin"
GOCACHE="/home/user/.cache/go-build"
GOENV="/home/user/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/media/user/sda7/golang/go-lib/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/media/user/sda7/golang/go-lib"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GOVCS=""
GOVERSION="go1.16.2"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/media/user/sda7/golang/go-lib/src/app/go.mod"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build3597029625=/tmp/go-build -gno-record-gcc-switches"

What did you do?

compile simple Hello World program to android/arm depending on this article https://rakyll.org/cross-compilation/
code:

package main
import "fmt"
func main() {
    fmt.Println("hello world")
}

GOOS=android GOARCH=arm GOARM=7 go build .

What did you expect to see?

app.apk

What did you see instead?

loadinternal: cannot find runtime/cgo
/usr/local/go/pkg/tool/linux_amd64/link: running gcc failed: exit status 1
gcc: error: unrecognized command line option ‘-marm’; did you mean ‘-mabm’?

@golang golang deleted a comment from cheater000 Mar 29, 2021
@tklauser
Copy link
Member

@tklauser tklauser commented Mar 29, 2021

FYI, I've deleted a comment which contained profanity and slurs. This didn't add anything to the issue itself and was in violation of the Go Community Code of Conduct.

@dr2chase dr2chase changed the title running gcc failed: exit status 1 when I try to compile simple hello world program to android/arm go/build: running gcc failed: exit status 1 when I try to compile simple hello world program to android/arm Mar 29, 2021
@dr2chase
Copy link
Contributor

@dr2chase dr2chase commented Mar 29, 2021

Are the right gcc cross-compilers installed?

@AlexRouSg
Copy link
Contributor

@AlexRouSg AlexRouSg commented Mar 29, 2021

I think the author is trying to do a no cgo build based on what the linked article is saying.
I remember somewhere that cgo/ndk is required for android (sometime after that article was posted) but I can't find anything to link to.

cc @eliasnaur

@m-abdalrahman
Copy link
Author

@m-abdalrahman m-abdalrahman commented Mar 29, 2021

Are the right gcc cross-compilers installed?

yes,

$ gcc --version 
gcc (Ubuntu 7.5.0-3ubuntu1~18.04) 7.5.0
Copyright (C) 2017 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.

@dr2chase

I think the author is trying to do a no cgo build based on what the linked article is saying.

yes, that's what I do @AlexRouSg

@eliasnaur
Copy link
Contributor

@eliasnaur eliasnaur commented Mar 29, 2021

See https://github.com/golang/go/tree/master/misc/android for getting started building programs for Android. @AlexRouSg is right that the NDK is needed, and if you want to use Go in apps you'll need -buildmode c-shared to build a shared library to use through JNI. There's also GoMobile for making it easier embedding and calling of Go libraries.

@eliasnaur
Copy link
Contributor

@eliasnaur eliasnaur commented Mar 29, 2021

What did you expect to see?

app.apk

The standard toolchain will definitely not output .apk (Android app) binaries. For that you need GoMobile, or perhaps even Fyne or (shameless plug) Gio

@golang golang deleted a comment from cheater000 Mar 30, 2021
@m-abdalrahman
Copy link
Author

@m-abdalrahman m-abdalrahman commented Mar 30, 2021

See https://github.com/golang/go/tree/master/misc/android for getting started building programs for Android. @AlexRouSg is right that the NDK is needed, and if you want to use Go in apps you'll need -buildmode c-shared to build a shared library to use through JNI. There's also GoMobile for making it easier embedding and calling of Go libraries.

thank you, this meaning the old implementation in the article has been changed
GOOS=android GOARCH=arm GOARM=7 go build .

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

Successfully merging a pull request may close this issue.

None yet
5 participants