Skip to content

Undefined __android_log_write on NDK builds #2719

@swansontec

Description

@swansontec

When I build Protocol Buffers 3.2.0 using the NDK, I get the following linker error:

libtool: link: arm-linux-androideabi-clang++ -std=c++11 -DHAVE_PTHREAD=1 -DHAVE_ZLIB=1 -Wall -Wno-sign-compare -isystem/Users/william/tmp/build/prefix/android/arm/include -fPIC -O2 -march=armv7-a -mfloat-abi=softfp -mfpu=vfpv3-d16 -mthumb -fPIC -march=armv7-a -Wl,--fix-cortex-a8 -o protoc google/protobuf/compiler/main.o  -L/Users/william/tmp/build/prefix/android/arm/lib ./.libs/libprotobuf.a ./.libs/libprotoc.a /Users/william/tmp/build/protobuf/android-arm/protobuf-3.2.0/src/.libs/libprotobuf.a -lz
/Users/william/tmp/build/protobuf/android-arm/protobuf-3.2.0/src/.libs/libprotobuf.a(common.o):google/protobuf/stubs/common.cc:function google::protobuf::internal::DefaultLogHandler(google::protobuf::LogLevel, char const*, int, std::__ndk1::basic_string<char, std::__ndk1::char_traits<char>, std::__ndk1::allocator<char> > const&): error: undefined reference to '__android_log_write'
/Users/william/tmp/build/protobuf/android-arm/protobuf-3.2.0/src/.libs/libprotobuf.a(common.o):google/protobuf/stubs/common.cc:function google::protobuf::internal::DefaultLogHandler(google::protobuf::LogLevel, char const*, int, std::__ndk1::basic_string<char, std::__ndk1::char_traits<char>, std::__ndk1::allocator<char> > const&): error: undefined reference to '__android_log_write'

There were no errors on 3.1.0 with an identical build setup.

Workaround

The problem is that -llog needs to be passed to the linker to make the __android_log_write function available. By temporarily defining LDFLAGS="-llog" before running configure, I can work around the problem. The Protocol Buffers configure script should be doing this automatically.

Build setup

I have extracted a standalone toolchain from the NDK, and have pointed my environment variables at the NDK-provided tools (CC, CCLD, CPP, CXX, LD, AR, AS, NM, OBJCOPY, OBJDUMP, RANLIB, STRINGS, STRIP). I run the standard build steps:

# Required by the NDK
export CFLAGS="-march=armv7-a -mfloat-abi=softfp -mfpu=vfpv3-d16 -mthumb"
export CXXFLAGS="-march=armv7-a -mfloat-abi=softfp -mfpu=vfpv3-d16 -mthumb"
export LDFLAGS="-march=armv7-a -Wl,--fix-cortex-a8"

# Normal build steps
autoreconf -i
./configure --enable-static --disable-shared --host=arm-linux-androideabi --with-protoc=protoc
make

The error occurs when running make.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions