-
Notifications
You must be signed in to change notification settings - Fork 18k
Having trouble building with Android NDK #42725
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
Comments
You’ll need to properly set your include paths. This isn’t a problem on Go’s end—clang is complaining. |
Hey @ericlagergren, thanks for the reply. When building the following C program with the same compiler: #include <android/log.h>
int main() {
} Like this: $NDK_ROOT/22.0.6917172/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android30-clang main.c It builds no problem. I verified that it's picking up the file So it appears the interaction with Go is somehow involved. Maybe the Go compiler is changing the sysroot when invoking the C compiler, which I'm not sure how to override. Any other ideas? |
Ok I believe this is sysroot related. If I run this command: GOOS=android GOARCH=arm64 CGO_ENABLED=1 CC_FOR_TARGET=$NDK_ROOT/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android30-clang CGO_CFLAGS="--sysroot=$NDK_ROOT/toolchains/llvm/prebuilt/linux-x86_64/sysroot" go build I get new errors: # runtime/cgo
In file included from /home/anders/Android/Sdk/ndk/22.0.6917172/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include/sys/types.h:36,
from /home/anders/Android/Sdk/ndk/22.0.6917172/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include/stdio.h:42,
from /home/anders/Android/Sdk/ndk/22.0.6917172/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include/malloc.h:30,
from /home/anders/Android/Sdk/ndk/22.0.6917172/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include/stdlib.h:34,
from /home/anders/Android/Sdk/ndk/22.0.6917172/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/local/include/stdlib.h:31,
from _cgo_export.c:3:
/home/anders/Android/Sdk/ndk/22.0.6917172/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include/linux/types.h:21:10: fatal error: asm/types.h: No such file or directory
21 | #include <asm/types.h>
| ^~~~~~~~~~~~~
compilation terminated. And sure enough that file doesn't exist in the NDK sysroot. I'm still missing something. If I change the simple C program in also include |
What happens if you set
|
Different error: # runtime/cgo
ld: error: duplicate symbol: x_cgo_inittls
>>> defined at gcc_android.c:90
>>> $WORK/b078/_x003.o:(x_cgo_inittls)
>>> defined at gcc_linux_arm64.c:15
>>> $WORK/b078/_x006.o:(.bss+0x8)
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Are you sure? I see it used in lots of cross compiling examples, and the docs mention it explicitly:
|
You didn't read the whole thing ...
The new errors are a dupe of #42655 which is NDK version related. |
Thank you. I've been beating my head against this for 2 days. I'll read more carefully next time. I can confirm that downgrading to NDK version 21 and using the following command (note NDK version 21 and CC instead of CC_FOR_TARGET) works for me: GOOS=android GOARCH=arm64 CGO_ENABLED=1 CC=$NDK_ROOT/21.3.6528147/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android30-clang go build |
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
I don't have the latest release.
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
I am attempting to build a go CLI program which I will then exec from an Android app and communicate with over HTTP.
Following the instructions here: https://github.com/golang/go/tree/master/misc/android
I tried to build the following go program
With this command:
What did you expect to see?
I would expect to see a go error that net/http is not used, which I could fix by using it...
What did you see instead?
The text was updated successfully, but these errors were encountered: