Skip to content

Instantly share code, notes, and snippets.

@alexst07
Forked from helayzhang/build_protobuf_android.sh
Last active August 29, 2015 14:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alexst07/8346ca2678feefab721b to your computer and use it in GitHub Desktop.
Save alexst07/8346ca2678feefab721b to your computer and use it in GitHub Desktop.
Fix link problems with gnustl
PREFIX=`pwd`/protobuf/android
rm -rf ${PREFIX}
mkdir ${PREFIX}
export NDK=YOUR_NDK_ROOT
# 1. Use the tools from the Standalone Toolchain
export PATH=YOUR_NDK_STAND_ALONE_TOOL_PATH/bin:$PATH
export SYSROOT=YOUR_NDK_STAND_ALONE_TOOL_PATH/sysroot
export CC="arm-linux-androideabi-gcc --sysroot $SYSROOT"
export CXX="arm-linux-androideabi-g++ --sysroot $SYSROOT"
export CXXSTL=$NDK/sources/cxx-stl/gnu-libstdc++/4.6
##########################################
# Fetch Protobuf 2.5.0 from source.
##########################################
(
cd /tmp
curl http://protobuf.googlecode.com/files/protobuf-2.5.0.tar.gz --output /tmp/protobuf-2.5.0.tar.gz
if [ -d /tmp/protobuf-2.5.0 ]
then
rm -rf /tmp/protobuf-2.5.0
fi
tar xvf /tmp/protobuf-2.5.0.tar.gz
)
cd /tmp/protobuf-2.5.0
mkdir build
# 3. Run the configure to target a static library for the ARMv7 ABI
# for using protoc, you need to install protoc to your OS first, or use another protoc by path
./configure --prefix=$(pwd)/build \
--host=arm-linux-androideabi \
--with-sysroot=$SYSROOT \
--disable-shared \
--enable-cross-compile \
--with-protoc=protoc \
CFLAGS="-march=armv7-a" \
CXXFLAGS="-march=armv7-a -I$CXXSTL/include -I$CXXSTL/libs/armeabi-v7a/include" \
LDFLAGS="-L$CXXSTL/libs/armeabi" \
LIBS="-lgnustl_static -static"
# 4. Build
make && make install
# 5. Inspect the library architecture specific information
arm-linux-androideabi-readelf -A build/lib/libprotobuf-lite.a
cp build/lib/libprotobuf.a $PREFIX/libprotobuf.a
cp build/lib/libprotobuf-lite.a $PREFIX/libprotobuf-lite.a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment