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

x/mobile/cmd/gomobile: build fails: clang80: error: argument unused during compilation: '-stdlib=libc++' [-Werror,-Wunused-command-line-argument] #29706

Closed
alx696 opened this issue Jan 12, 2019 · 5 comments
Labels
FrozenDueToAge mobile Android, iOS, and x/mobile
Milestone

Comments

@alx696
Copy link

alx696 commented Jan 12, 2019

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

go version go1.11.4 linux/amd64

Android NDK 19.0.5160253-beta2

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
GOARCH="amd64"
GOBIN="/home/x/go/bin"
GOCACHE="/home/x/.cache/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/x/go"
GOPROXY=""
GORACE=""
GOROOT="/home/x/app/go"
GOTMPDIR=""
GOTOOLDIR="/home/x/app/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD=""
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-build212459853=/tmp/go-build -gno-record-gcc-switches"

What did you do?

Run gomobile build to build an Android APK.

https://github.com/golang/go/wiki/Mobile#building-and-deploying-to-android

What did you expect to see?

Build command will build an APK named basic.apk.

What did you see instead?

x@xpc:~$ gomobile build -target=android golang.org/x/mobile/example/basic
gomobile: go build -buildmode=c-shared -o /tmp/gomobile-work-451339240/lib/armeabi-v7a/libbasic.so golang.org/x/mobile/example/basic failed: exit status 2
# runtime/cgo
clang80: error: argument unused during compilation: '-stdlib=libc++' [-Werror,-Wunused-command-line-argument]
gomobile build -target=android -x golang.org/x/mobile/example/basic Output
x@xpc:~$ gomobile build -target=android -x golang.org/x/mobile/example/basic
GOMOBILE=/home/x/go/pkg/gomobile
WORK=/tmp/gomobile-work-944186541
mkdir -p $WORK/lib/armeabi-v7a
GOOS=android GOARCH=arm CC=$GOMOBILE/ndk-toolchains/arm/bin/arm-linux-androideabi-clang CXX=$GOMOBILE/ndk-toolchains/arm/bin/arm-linux-androideabi-clang++ CGO_ENABLED=1 GOARM=7 go build -x -buildmode=c-shared -o $WORK/lib/armeabi-v7a/libbasic.so golang.org/x/mobile/example/basic
rm -r -f "$WORK"
gomobile: go build -x -buildmode=c-shared -o /tmp/gomobile-work-944186541/lib/armeabi-v7a/libbasic.so golang.org/x/mobile/example/basic failed: exit status 2
WORK=/tmp/go-build950337788
mkdir -p $WORK/b041/
cd /home/x/app/go/src/runtime/cgo
CGO_LDFLAGS='"-g" "-O2" "-llog"' /home/x/app/go/pkg/tool/linux_amd64/cgo -objdir $WORK/b041/ -importpath runtime/cgo -import_runtime_cgo=false -import_syscall=false -exportheader=$WORK/b041/_cgo_install.h -- -I $WORK/b041/ -g -O2 -Wall -Werror ./cgo.go
# runtime/cgo
clang80: error: argument unused during compilation: '-stdlib=libc++' [-Werror,-Wunused-command-line-argument]
@gopherbot gopherbot added this to the Unreleased milestone Jan 12, 2019
@gopherbot gopherbot added the mobile Android, iOS, and x/mobile label Jan 12, 2019
@unicameralontology
Copy link

I got this same error on go1.11.4 windows/amd64 and NDK 19.0.5232133, and got around it by making this change to an NDK script: https://android-review.googlesource.com/c/platform/ndk/+/875216

--- a/build/tools/make_standalone_toolchain.py
+++ b/build/tools/make_standalone_toolchain.py
@@ -127,7 +127,7 @@
 
     triple = get_triple(arch)
     target = make_clang_target(triple, api)
-    flags = '-target {} -stdlib=libc++'.format(target)
+    flags = '-target {}'.format(target)

and then running gomobile init again.

Seems to be related to this issue in NDK: android/ndk#849

@alx696
Copy link
Author

alx696 commented Jan 19, 2019

@unicameralontology Thanks! After remove -stdlib=libc++ from path_to_ndk/build/tools/make_standalone_toolchain.py in line 124, error gone away.

@alx696 alx696 closed this as completed Jan 19, 2019
@beansgum
Copy link

Any way to fix this in CI build?

@wejoy
Copy link

wejoy commented Mar 4, 2019

When I run:

gomobile bind -target=android testmobile

I got this:

C:\User\GOPATH\bin\gomobile.exe: go build -buildmode=c-shared -o=C:\User\AppData\Local\Temp\gomobile-work-329945059\android\src\main\jniLibs\armeabi-v7a\libgojni.so gobind failed: exit status 2
# runtime/cgo
clang++.exe: error: treating 'c' input as 'c++' when in C++ mode, this behavior is deprecated [-Werror,-Wdeprecated]

go version:

go version go1.11.4 windows/amd64

go env:

set GOARCH=amd64
set GOBIN=
set GOCACHE=C:\User\AppData\Local\go-build
set GOEXE=.exe
set GOFLAGS=
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOOS=windows
set GOPATH=C:\User\GOPATH
set GOPROXY=
set GORACE=
set GOROOT=C:\Go
set GOTMPDIR=
set GOTOOLDIR=C:\Go\pkg\tool\windows_amd64
set GCCGO=gccgo
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:\User\AppData\Local\Temp\go-build327219370=/tmp/go-build -gno-record-gcc-switches

NDK Version:

19.1.5304403

Does anyone know what's going on?

@beansgum
Copy link

beansgum commented Mar 4, 2019

I fixed mine some time ago by manually downloading a specific version of ndk where I know I won't encounter this error.

wget -O $ANDROID_HOME/android-ndk-r19b-linux-x86_64.zip https://dl.google.com/android/repository/android-ndk-r19b-linux-x86_64.zip
unzip -qq $ANDROID_HOME/android-ndk-r19b-linux-x86_64.zip -d $ANDROID_HOME/android-ndk-r19b-linux-x86_64
mv $ANDROID_HOME/android-ndk-r19b-linux-x86_64/android-ndk-r19b $ANDROID_HOME/ndk-bundle
export ANDROID_NDK_HOME=$ANDROID_HOME/ndk-bundle

Here's my complete CI script

@golang golang locked and limited conversation to collaborators Mar 3, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge mobile Android, iOS, and x/mobile
Projects
None yet
Development

No branches or pull requests

5 participants