下载交叉编译链
wget https://snapshots.linaro.org/gnu-toolchain/11.3-2022.06-1/aarch64-linux-gnu/gcc-linaro-11.3.1-2022.06-x86_64_aarch64-linux-gnu.tar.xz
wget https://snapshots.linaro.org/gnu-toolchain/11.3-2022.06-1/aarch64-linux-gnu/sysroot-glibc-linaro-2.34-2022.06-aarch64-linux-gnu.tar.xz
下载protobuf
wget https://github.com/protocolbuffers/protobuf/archive/refs/tags/v3.5.1.tar.gz
编译
tar xvf v3.5.1.tar.gz
cd protobuf-3.5.1
mkdir install
./autogen.sh
配置
-
用选型CC/CXX指定交叉编译链
-
用--with-sysroot指定sysroot路径
-
--prefix执行安装目录的路径
-
--host指定目标host平台型号
-
--with-protoc=protoc 可以指定用protoc协助编译,前提是要安装 protobuf-compiler
./configure --target=aarch64-linux --host=aarch64-linux --with-sysroot=~/sysroot-glibc-linaro-2.34-2022.06-aarch64-linux-gnu CC=~/gcc-linaro-11.3.1-2022.06-x86_64_aarch64-linux-gnu/bin/aarch64-linux-gnu-gcc CXX=~/gcc-linaro-11.3.1-2022.06-x86_64_aarch64-linux-gnu/bin/aarch64-linux-gnu-g++ --prefix=~/protobuf-3.5.1/install
./configure --host=aarch64-linux-gnu --with-sysroot=~/sysroot-glibc-linaro-2.34-2022.06-aarch64-linux-gnu CC=~/gcc-linaro-11.3.1-2022.06-x86_64_aarch64-linux-gnu/bin/aarch64-linux-gnu-gcc CXX=~/gcc-linaro-11.3.1-2022.06-x86_64_aarch64-linux-gnu/bin/aarch64-linux-gnu-g++ --prefix=~/protobuf-3.5.1/install
实际也可以直接指定host平台即可 :
./autogen.sh
./configure --with-protoc=protoc --host=aarch64-linux-gnu --prefix=~/protobuf-3.5.1/install
make
make install
编译
make -j8
make 报错,找不到ld-linux-aarch64.so.1
将sysroot目录下的ld-linux-aarch64.so.1拷贝到系统目录/lib/ld-linux-aarch64.so.1
添加依赖库路径: ** 实测无效,需要拷贝。**
- export LDFLAGS=~/sysroot-glibc-linaro-2.34-2022.06-aarch64-linux-gnu/libc/lib/
- export LDFLAGS_FOR_BUILD=~/sysroot-glibc-linaro-2.34-2022.06-aarch64-linux-gnu/libc/lib/
make报错:找不到libstdc++
protobuf-3.5.1/src/.libs/lt-protoc: error while loading shared libraries: libstdc++.so.6: cannot open shared object file: No such file or directory
make[2]: *** [Makefile:9508:unittest_proto_middleman] 错误 127
- 后面发现可能是配置问题,修改了配置host为aarch64-linux-gnu 即可
dockers 安装编译 - success
apt-get install autoconf automake libtool
./autogen.sh
// ./configure --with-protoc=protoc --host=aarch64-linux-gnu --prefix=/app/protobuf-3.5.1/install
./configure --host=aarch64-linux-gnu --prefix=/app/protobuf-3.5.1/install
make
make install