dqudtskm49788
dqudtskm49788
2017-06-07 23:29

编译到Android: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: 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条回答

  • douyinliu8813 douyinliu8813 4年前

    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

    点赞 评论 复制链接分享

为你推荐