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

cmd/go: unrecognized command line option '-rdynamic' when compiling to Android #40988

Open
hajsf opened this issue Aug 23, 2020 · 1 comment
Open

Comments

@hajsf
Copy link

@hajsf hajsf commented Aug 23, 2020

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

$ go version
go version go1.15 windows/amd64

Does this issue reproduce with the latest release? Yes

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

go env Output
$ go env
PS C:\Users\hasan> go env
set GO111MODULE=
set GOARCH=amd64
set GOBIN=C:\go\bin
set GOCACHE=C:\Users\hasan\AppData\Local\go-build
set GOENV=C:\Users\hasan\AppData\Roaming\go\env
set GOEXE=.exe
set GOFLAGS=
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOINSECURE=
set GOMODCACHE=C:\Users\hasan\Documents\GoWorkPlace\pkg\mod
set GONOPROXY=
set GONOSUMDB=
set GOOS=windows
set GOPATH=C:\Users\hasan\Documents\GoWorkPlace
set GOPRIVATE=
set GOPROXY=https://proxy.golang.org,direct
set GOROOT=c:\go
set GOSUMDB=sum.golang.org
set GOTMPDIR=
set GOTOOLDIR=c:\go\pkg\tool\windows_amd64
set GCCGO=gccgo
set AR=ar
set CC=gcc
set CXX=g++
set CGO_ENABLED=1
set GOMOD=
set CGO_CFLAGS=-g -O2
set CGO_CPPFLAGS=
set CGO_CXXFLAGS=-g -O2
set CGO_FFLAGS=-g -O2
set CGO_LDFLAGS=-g -O2
set PKG_CONFIG=pkg-config
set GOGCCFLAGS=-m64 -mthreads -fmessage-length=0 -fdebug-prefix-map=C:\Users\hasan\AppData\Local\Temp\go-build663873386=/tmp/go-build -gno-record-gcc-switches

What did you do?

build.go

package main

import (
	"fmt"
	"os"
	"os/exec"
)

type compiles struct {
	sys  string
	arch string
}

func main() {
	var output string
	// go tool dist list
	systems := []compiles{
		compiles{
			sys:  "darwin",
			arch: "amd64",
		},
		compiles{
			sys:  "android",
			arch: "amd64",
		},
		compiles{
			sys:  "linux",
			arch: "amd64",
		},
	}

	for _, s := range systems {
		os.Setenv("GOOS", s.sys)
		os.Setenv("GOARCH", s.arch)
		switch println(s.sys); s.sys {
		case "darwin":
			output = "output.dmg"
		case "android", "linux":
			//os.Setenv("CC", "arm-none-eabi-gcc")
			output = "output"
		default:
			println("Undefined")
		}
		cmd := exec.Command("go", "build", "-o", output, "main.go")
		out, err := cmd.CombinedOutput()
		if err != nil {
			fmt.Printf("cmd.Run() failed with %v:\n\noutput:\n\n%s\n", err, out)
		}
	}
}

What did you expect to see?

By running go run build.go I expect cross compiling for the specified systems, and getting 3 binary files generated, 1 for Apple, 1 for Linux and 1 for Android.

What did you see instead?

I get 2 (for Apple and Linux) and got error at the time of building the one for Android

C:\Users\hasan\Documents\GoPlay\Env>go run build.go
darwin
android
cmd.Run() failed with exit status 2:

output:

# command-line-arguments
c:\go\pkg\tool\windows_amd64\link.exe: running gcc failed: exit status 1
gcc: error: unrecognized command line option '-rdynamic'


linux
@ALTree
Copy link
Member

@ALTree ALTree commented Aug 23, 2020

This may be a dup of (or related to) #36633. More specifically, it looks like your gcc cross compiler does not support -rdynamic.

@ALTree ALTree changed the title Unrecognized command line option '-rdynamic' when compiling to Android cmd/go: unrecognized command line option '-rdynamic' when compiling to Android Aug 23, 2020
@jayconrod jayconrod added this to the Unplanned milestone Sep 21, 2020
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
3 participants
You can’t perform that action at this time.