简体   繁体   English

为 Android 构建谷歌 protobug 库时出错

[英]Error on build google protobug lib for Android

I want to use protobuf in native c++ code in Android.我想在 Android 的本机 c++ 代码中使用 protobuf。 I have done the steps descriped in https://developers.google.com/cardboard/develop/c/protobuf .我已经完成了https://developers.google.com/cardboard/develop/c/protobuf中描述的步骤。 But it stucks on cross compiling the protobuflib with:但它坚持交叉编译protobuflib:

/tmp/protobuf/../arm-21-toolchain-clang-32/sysroot/usr/lib/../lib/crtbegin_dynamic.o:crtbegin.c:function _start: error: undefined reference to 'main'
clang50++: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [protoc] Error 1

and

  CXXLD    protoc
./.libs/libprotobuf.a: error adding symbols: Archive has no index; run ranlib to add one
clang50++: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [protoc] Error 1

I am using this script for building:我正在使用此脚本进行构建:

cd /tmp


### Cross-compile Protocol Buffers library ###
#git clone https://github.com/protocolbuffers/protobuf.git
cd /tmp/protobuf
git checkout v3.10.1
git submodule update --init --recursive
./autogen.sh
mkdir -p `pwd`/../libprotobuf/android

## buildscript32
export build_dir=`pwd`/../libprotobuf/android
export sysroot=`pwd`/../arm-21-toolchain-clang-32/sysroot
export PATH=`pwd`/../arm-21-toolchain-clang-32/bin:$PATH
export CC="arm-linux-androideabi-clang --sysroot $sysroot"
export CXX="arm-linux-androideabi-clang++ --sysroot $sysroot"

./configure \
--host=arm-linux-androideabi \
--with-protoc=protoc \
--with-sysroot="$sysroot" \
--disable-shared \
--prefix="$build_dir/armeabi-v7a" \
--enable-cross-compile \
CFLAGS="-march=armv7-a -D__ANDROID_API__=21" \
CXXFLAGS="-frtti -fexceptions -march=armv7-a -D__ANDROID_API__=21" \
LIBS="-llog -lz -lc++_static"

make -j8
make install


## clean 
make distclean


## buildscript64
export build_dir=`pwd`/../libprotobuf/android
export sysroot=`pwd`/../arm-21-toolchain-clang-64/sysroot
export PATH=`pwd`/../arm-21-toolchain-clang-64/bin:$PATH
export CC="aarch64-linux-android-clang --sysroot $sysroot"
export CXX="aarch64-linux-android-clang++ --sysroot $sysroot"

./configure \
--host=arm-linux-androideabi \
--with-protoc=protoc \
--with-sysroot="$sysroot" \
--disable-shared \
--prefix="$build_dir/arm64-v8a" \
--enable-cross-compile \
CFLAGS="-march=armv8-a -D__ANDROID_API__=21" \
CXXFLAGS="-frtti -fexceptions -march=armv8-a -D__ANDROID_API__=21" \
LIBS="-llog -lz -lc++_static"

make -j8
make install

## generate file structure
mkdir -p ../libprotobuf/android/lib/armeabi-v7a
mkdir -p ../libprotobuf/android/lib/arm64-v8a
cp ../libprotobuf/android/armeabi-v7a/lib/libprotobuf-lite.a ../libprotobuf/android/lib/armeabi-v7a
cp ../libprotobuf/android/arm64-v8a/lib/libprotobuf-lite.a ../libprotobuf/android/lib/arm64-v8a
cp -r ../libprotobuf/android/armeabi-v7a/include ../libprotobuf/android/include
rm -rf ../libprotobuf/android/armeabi-v7a
rm -rf ../libprotobuf/android/arm64-v8a
### End: Cross-compile Protocol Buffers library ###

How do I build libprotobuf for Android??如何为 Android 构建 libprotobuf? Host is linux-x86_64 Thank you主机是 linux-x86_64 谢谢

I had the same issue building doing a cross compile for Android using the clang based NDK.我在使用基于 clang 的 NDK 为 Android 进行交叉编译时遇到了同样的问题。 I simply did a post step of 'ranlib libprotobuf.a' and it worked.我只是做了一个“ranlib libprotobuf.a”的发布步骤,它起作用了。

I'm using v3.11.4我正在使用 v3.11.4

My script is as follows: (I'm using ubuntu 16.04 with NDK 21 for android27 with an arm64v8a target) (in the path, ndk-bundle is likely "/ndk/21.0.6113669/" or something like that)我的脚本如下:(我使用 ubuntu 16.04 和 NDK 21 用于带有 arm64v8a 目标的 android27)(在路径中,ndk-bundle 可能是“/ndk/21.0.6113669/”或类似的东西)

create a directory called 'android_build' and run the following from there:创建一个名为“android_build”的目录并从那里运行以下命令:

export PREFIX=$HOME/protobuf_android/
export PATH=$HOME/Android/Sdk/ndk-bundle/toolchains/llvm/prebuilt/linux-x86_64/bin/:$PATH
export SYSROOT=$HOME/Android/Sdk/ndk-bundle/toolchains/llvm/prebuilt/linux-x86_64/sysroot/
export CC="aarch64-linux-android27-clang --sysroot $SYSROOT"
export CXX="aarch64-linux-android27-clang++ --sysroot $SYSROOT"

../configure \
    --prefix=$PREFIX \
    --host=arm-linux-androideabi \
    --with-sysroot="${SYSROOT}" \
    --enable-shared \
    --enable-cross-compile \
    --with-protoc=protoc \
    CFLAGS="-march=arm64v8-a -D__ANDROID_API__=27" \
    CXXFLAGS="-frtti -fexceptions -march=arm64v8-a -D__ANDROID_API__=27" \
    LIBS="-llog -lz -lc++_static"

make -j4

make install

/usr/bin/ranlib ${PREFIX}/lib/libprotobuf.a

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Android appcompat lib + design lib =构建错误 - Android appcompat lib + design lib = build error android 构建 static 库 - android build static lib Android AOSP 构建错误与第三方库(如 Firebase)-“appname”取决于未定义的模块“com.google.firebase_firebase-core” - Android AOSP build error with third party lib like Firebase - “appname” depends on undefined module “com.google.firebase_firebase-core” Android - 找不到google-play-services_lib.apk! 错误 - Android - Could not find google-play-services_lib.apk! error Android应用程序-在Google Play上找不到本机lib错误报告吗? - Android app - native lib not found error report on Google Play? android-apt-compiler:[google-play-services_lib] Android SDK中没有构建工具 - android-apt-compiler: [google-play-services_lib] No Build Tools in the Android SDK Android:ANT版本因google-play-services-lib而失败:“解析为没有project.properties文件的路径” - Android: ANT build fails with google-play-services-lib: “resolve to a path with no project.properties file for project” Google Play游戏在Android版本中发生错误超时 - Error timeout by Google Play Games in android build 建立Google Breakpad Android示例错误 - build google breakpad android sample error 在Android中使用LibPhoneNumber谷歌库 - Using LibPhoneNumber google lib in Android
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM