交叉编译Brpc,环境搭建和编译

交叉编译Brpc

一、交叉编译环境准备

1.虚拟机:Ubuntu18.04

2.刷新当前的shell环境为SDK的环境变量

source /xx/xx/environment-setup-aarch64-xx-linux

3.库的安装目录为SDK里库的安装位置:/xx/xx/sysroots/aarch64-xx-linux/usr/

二、 移植gflags

git clone https://github.com/gflags/gflags.git
mkdir gflags_lib
cd gflags
mkdir build
cd build
cmake -DCMAKE_INSTALL_PREFIX=../../gflags_lib ..
make -j4
make install
cd ../../gflags_lib/
mv lib lib64
sudo cp -r bin include lib64 /xx/xx/sysroots/aarch64-xx-linux/usr/

三、移植 leveldb

git clone https://github.com/google/leveldb.git
mkdir leveldb_lib
cd leveldb/third_party
git clone https://github.com/google/googletest.git
git clone https://github.com/google/benchmark.git
cd ..
mkdir build
cd build
cmake -DCMAKE_INSTALL_PREFIX=../../leveldb_lib ..
make -j4
make install
cd ../../leveldb_lib
mv lib lib64
sudo cp -r include lib64 share /xx/xx/sysroots/aarch64-xx-linux/usr/

四、移植protobuf

1.首先先编译x86环境下的protobuf,需要重新打开一个新的shell终端,不要soure SDK的环境变量

git clone https://github.com/protocolbuffers/protobuf.git
mkdir protobuf_lib
cd protobuf
git checkout v2.6.1

vim autogen.sh
将下面这段:
if test ! -e gtest; then
  echo "Google Test not present.  Fetching gtest-1.5.0 from the web..."
  curl http://googletest.googlecode.com/files/gtest-1.5.0.tar.bz2 | tar jx
  mv gtest-1.5.0 gtest
fi
修改为:
if test ! -e gtest; then
  echo "Google Test not present.  Fetching gtest-1.5.0 from the web..."
  wget https://github.com/google/googletest/archive/release-1.5.0.tar.gz
  tar xzvf release-1.5.0.tar.gz
  mv googletest-release-1.5.0 gtest
fi

./autogen.sh
./configure --prefix=/usr/local/protobuf
make -j4
sudo make install
make distclean

2.回到source过SDK环境变量的终端

cd protobuf
export PATH=$PATH:/usr/local/protobuf/bin
export PKG_CONFIG_PATH=/usr/local/protobuf/lib/pkgconfig
export LIBRARY_PATH=$LIBRARY_PATH:/usr/local/protobuf/lib
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/protobuf/lib
protoc --version

./configure --prefix=/xx/xx/xx/protobuf_lib --host=aarch64-xx-linux  
--with-protoc=protoc

make -j4
make install
cd ../protobuf_lib
mv lib lib64
sudo cp -r bin include lib64 /xx/xx/sysroots/aarch64-xx-linux/usr/

五、移植Brpc

git clone https://github.com/apache/brpc.git
mkdir brpc_lib
cd brpc
git checkout release-1.3

vim CMakeLists.txt
添加两行以下命令
set(CMAKE_LIBRARY_PATH "/usr/lib64")
link_directories("/usr/lib64")

mkdir build 
cd build
cmake -DCMAKE_INSTALL_PREFIX=../../brpc_lib ..
make -j4
make install
cd ../../brpc_lib/
mv lib lib64
sudo cp -r include lib64 /xx/xx/sysroots/aarch64-xx-linux/usr/

你可能感兴趣的:(linux,c++,rpc)