英文:
Compiling go to Android: invalid signature of pthread_key_create
问题
CGO_CFLAGS = "--sysroot = android-sdk-linux/ndk-bundle/platforms/android-9/arch-arm/"
CGO_ENABLED = 1 CC = android-sdk-linux/ndk-bundle/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin/arm-linux-androideabi-g++ CXX = android-sdk-linux/ndk-bundle/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin/arm-linux-androideabi-g++
GOOS = android GOARCH = arm go build -buildmode = c-archive --ldflags = "--sysroot = android-sdk-linux/ndk-bundle/platforms/android-9/arch-arm/"
runtime/cgo
/usr/lib/go-1.8/src/runtime/cgo/gcc_android_arm.c:在函数'inittls(void **,void **)'中:
/usr/lib/go-1.8/src/runtime/cgo/gcc_android_arm.c:30:34:错误:从'void '到'void ()(void )'的无效转换[-fpermissive]
err = pthread_key_create(&k,nil);
^
在文件包含自/usr/lib/go-1.8/src/runtime/cgo/gcc_android_arm.c:5:0:
/home/janus/Desktop/android-sdk-linux/ndk-bundle/platforms/android-9/arch-arm/usr/include/pthread.h:265:5:注意:初始化参数2的'int pthread_key_create(pthread_key_t * key,void ( destructor_function)(void ))'
int pthread_key_create(pthread_key_t * key,void ( destructor_function)(void *));
最新的API级别(如22)也存在相同的问题。
我正在使用https://github.com/golang/go/wiki/Ubuntu上提到的golang-1.8-go软件包。
英文:
CGO_CFLAGS="--sysroot=android-sdk-linux/ndk-bundle/platforms/android-9/arch-arm/" CGO_ENABLED=1 CC=android-sdk-linux/ndk-bundle/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin/arm-linux-androideabi-g++ CXX=android-sdk-linux/ndk-bundle/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin/arm-linux-androideabi-g++ \
GOOS=android GOARCH=arm go build -buildmode=c-archive --ldflags="--sysroot=android-sdk-linux/ndk-bundle/platforms/android-9/arch-arm/"
# runtime/cgo
/usr/lib/go-1.8/src/runtime/cgo/gcc_android_arm.c: In function 'void inittls(void**, void**)':
/usr/lib/go-1.8/src/runtime/cgo/gcc_android_arm.c:30:34: error: invalid conversion from 'void*' to 'void (*)(void*)' [-fpermissive]
err = pthread_key_create(&k, nil);
^
In file included from /usr/lib/go-1.8/src/runtime/cgo/gcc_android_arm.c:5:0:
/home/janus/Desktop/android-sdk-linux/ndk-bundle/platforms/android-9/arch-arm/usr/include/pthread.h:265:5: note: initializing argument 2 of 'int pthread_key_create(pthread_key_t*, void (*)(void*))'
int pthread_key_create(pthread_key_t *key, void (*destructor_function)(void *));
The same issue occurs with recent API levels like 22.
I am using the golang-1.8-go package mentioned on https://github.com/golang/go/wiki/Ubuntu
答案1
得分: 0
编译器命令不完整。您可以使用gomobile build -x
查看如何正确调用编译器,记住您可能需要在shell中正确引用参数。
以下是一个正确的命令示例:
GOMOBILE=/home/janus/go/pkg/gomobile GOPATH=$HOME/go ANDROID_HOME=/home/janus/Desktop/android-sdk-linux GOOS=android GOARCH=arm CC=$ANDROID_HOME/ndk-bundle/toolchains/llvm/prebuilt/linux-x86_64/bin/clang CXX=$ANDROID_HOME/ndk-bundle/toolchains/llvm/prebuilt/linux-x86_64/bin/clang++ CGO_CFLAGS="-target armv7a-none-linux-androideabi --sysroot $ANDROID_HOME/ndk-bundle/platforms/android-15/arch-arm -gcc-toolchain $ANDROID_HOME/ndk-bundle/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64 -I$GOMOBILE/include" CGO_CPPFLAGS="-target armv7a-none-linux-androideabi --sysroot $ANDROID_HOME/ndk-bundle/platforms/android-15/arch-arm -gcc-toolchain $ANDROID_HOME/ndk-bundle/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64 -I$GOMOBILE/include" CGO_LDFLAGS="-target armv7a-none-linux-androideabi --sysroot $ANDROID_HOME/ndk-bundle/platforms/android-15/arch-arm -gcc-toolchain $ANDROID_HOME/ndk-bundle/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64 -L$ANDROID_HOME/ndk-bundle/platforms/android-15/arch-arm/usr/lib -L$GOMOBILE/lib/arm" CGO_ENABLED=1 GOARM=7 go build -pkgdir=$GOMOBILE/pkg_android_arm -buildmode=c-shared
英文:
The compiler command is incomplete. You can use gomobile build -x
to see how to invoke the compiler correctly, remember you might need to quote the parameters correctly in your shell.
An example of a correct command:
GOMOBILE=/home/janus/go/pkg/gomobile GOPATH=$HOME/go ANDROID_HOME=/home/janus/Desktop/android-sdk-linux GOOS=android GOARCH=arm CC=$ANDROID_HOME/ndk-bundle/toolchains/llvm/prebuilt/linux-x86_64/bin/clang CXX=$ANDROID_HOME/ndk-bundle/toolchains/llvm/prebuilt/linux-x86_64/bin/clang++ CGO_CFLAGS="-target armv7a-none-linux-androideabi --sysroot $ANDROID_HOME/ndk-bundle/platforms/android-15/arch-arm -gcc-toolchain $ANDROID_HOME/ndk-bundle/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64 -I$GOMOBILE/include" CGO_CPPFLAGS="-target armv7a-none-linux-androideabi --sysroot $ANDROID_HOME/ndk-bundle/platforms/android-15/arch-arm -gcc-toolchain $ANDROID_HOME/ndk-bundle/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64 -I$GOMOBILE/include" CGO_LDFLAGS="-target armv7a-none-linux-androideabi --sysroot $ANDROID_HOME/ndk-bundle/platforms/android-15/arch-arm -gcc-toolchain $ANDROID_HOME/ndk-bundle/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64 -L$ANDROID_HOME/ndk-bundle/platforms/android-15/arch-arm/usr/lib -L$GOMOBILE/lib/arm" CGO_ENABLED=1 GOARM=7 go build -pkgdir=$GOMOBILE/pkg_android_arm -buildmode=c-shared
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论