I’m having trouble building Protocol Buffers for Android using a standalone NDK toolchain created with the $NDK/build/tools/make-standalone-toolchain.sh script. The problem I’m having is this:
libtool: link: g++ -Wall -Wwrite-strings -Woverloaded-virtual -Wno-sign-compare -O2 -g -DNDEBUG -o protoc main.o ./.libs/libprotobuf.a ./.libs/libprotoc.a /home/sizeak/AudioFingerprinting/ProtoBuf/jni/src/.libs/libprotobuf.a -lz -lc
./.libs/libprotoc.a(plugin.pb.o): In function `GoogleOnceInit':
/home/sizeak/AudioFingerprinting/ProtoBuf/jni/src/./google/protobuf/stubs/once.h:115: undefined reference to `pthread_once'
Which seems to imply that the pthreads library is missing, however the sysroot was created by the ndk script so should contain everything, right? I read somewhere that it is unnecessary to explicitly link pthreads when using the standalone toolchain. The configure command I used was:
./configure --host=arm-eabi --with-sysroot=$SYSROOT CC=$CC --enable-cross-compile --with-protoc=protoc LIBS="-lc"
Where the environment variables are set up to point at the sysroot created by the script.
I’ve seen this problem on a number of pages on the net, but no one seems to have posted an answer. Can anyone help?
I managed to build it using the ndk-build method, using information found here: How to build protocol buffer by Android NDK
To setup the configure script, I ran these commands:
This is the Application.mk I used:
And the Android.mk used:
To include the built library in my other NDK project that I’m using Protocol Buffers in, I had to copy the library into the jni folder of the project using the library and modify its Android.mk to add a reference to it:
I think that’s it, hope someone finds it useful.