为ARM交叉编译protobuf时出错:./.libs/libprotoc.so: error: undefined reference to 'descriptor

sen*_*nmu 5 android cross-compiling protocol-buffers

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
Run Code Online (Sandbox Code Playgroud)

配置没有错误,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
Run Code Online (Sandbox Code Playgroud)

环境

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

有趣的是,虽然报错,但是在protobuf/src/.libs下获取了.so等库文件。

小智 1

在 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:这不会发生,这里是Qt 论坛上有关该主题的aarch64-linux-android 链接。

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