首页 > 解决方案 > 为 ARM:./.libs/libprotoc.so 交叉编译 protobuf 时出错:error: undefined reference to 'descriptor

问题描述

为 ARM 交叉编译 protobuf 时出错

编译脚本:

  1 #!/bin/sh
  2 
  3 export PREFIX=$HOME/soft/protobuf_arm/
  4 CLANG_TOOLCHAIN=$HOME/soft/arm-29-toolchain-clang
  5 export PATH=$CLANG_TOOLCHAIN/bin:$PATH
  6 export SYSROOT=$CLANG_TOOLCHAIN/sysroot
  7 export CC="armv7a-linux-androideabi29-clang --sysroot $SYSROOT"
  8 export CXX="armv7a-linux-androideabi29-clang++ --sysroot $SYSROOT"
  9 
 10 cd $HOME/github/c++/protobuf
 11 make clean
 12 ./autogen.sh
 13 ./configure --prefix=$PREFIX \
 14 --host=armv7a-linux-androideabi29 \
 15 --with-sysroot="${SYSROOT}" \
 16 --enable-shared \
 17 --enable-cross-compile \
 18 --with-protoc=$HOME/soft/protobuf_linux/protoc \
 19 CFLAGS="-march=armv7-a -D__ANDROID_API__=29" \
 20 CXXFLAGS="-frtti -fexceptions -march=armv7-a -D__ANDROID_API__=29" \
 21 LIBS="-llog -lz -lc++_static"
 22 make -j 12
 23 make install

configure没有错误,make有错误:

In file included from google/protobuf/compiler/csharp/csharp_source_generator_base.cc:39:
./google/protobuf/compiler/csharp/csharp_source_generator_base.h:62:25: warning: private field 'descriptor_' is not used [-Wunused-private-field]
  const FileDescriptor* descriptor_;
                        ^
1 warning generated.
  CXXLD    libprotoc.la
clang90++: warning: argument unused during compilation: '-pthread' [-Wunused-command-line-argument]
clang90++: warning: argument unused during compilation: '-pthread' [-Wunused-command-line-argument]
  CXXLD    protoc
./.libs/libprotoc.so: error: undefined reference to 'descriptor_table_google_2fprotobuf_2fdescriptor_2eproto'
./.libs/libprotoc.so: error: undefined reference to 'scc_info_FileDescriptorProto_google_2fprotobuf_2fdescriptor_2eproto'
clang90++: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [Makefile:3883: protoc] Error 1
make[2]: Leaving directory '/home/sen/github/c++/protobuf/src'
make[1]: *** [Makefile:1866: all-recursive] Error 1
make[1]: Leaving directory '/home/sen/github/c++/protobuf'
make: *** [Makefile:1773: all] Error 2

环境

Linux x 5.6.15-arch1-1
GNU Make 4.3
NDK (Side by side) 21.1.6352462
protobuf v3.13.0

有意思的是,虽然报错了,但是在protobuf/src/.libs下得到了.so等库文件。

标签: androidprotocol-bufferscross-compiling

解决方案


在 Linux (debian 4.19.0-16-amd64) 上编译时我也遇到了这个错误armv7a-linux-androideabi

正如您所说,这“没问题”,因为库是在其中创建的src/.libs并且它们似乎工作正常(至少libprotobuf.so

我使用旧版本的 ndk-r21 (Pkg.Revision = 21.0.6113669) 没有问题,我最近更新到最新的 ndk-r21e (21.4.7075529),我发现这是问题所在...

PS:这不是发生在aarch64-linux-android 这里是Qt论坛上关于该主题的链接。

对于那些感兴趣的人,这是我构建 x86_64 版本和 Android 32 位和 64 位的编译脚本。


推荐阅读