-
Notifications
You must be signed in to change notification settings - Fork 263
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[BUG] Building a program with protobuf results in undefined references #896
Comments
because the libc++ in the version of the NDK you're using isn't necessarily the same as (ABI-compatible-with) the one in the version of the platform you're targeting.
that's explicitly not supported. https://android-developers.googleblog.com/2016/06/improving-stability-with-private-cc.html you'll need to build your own protobuf libraries. |
Thanks very much for quick reply. However, if I build my own protobuf libraries, e.g., shared protobuf libraries, will it conflict with the shared protobuf libraries in Android? |
it shouldn't be a problem. if you're worried, you can always build them with a different soname (or just link all your libraries together). |
For example, if there is a function named A_foo in protobuf, since I have two sets of protobuf library in Android (one built by myself, the other from Android), even the libraries have distinct names, however, they will have the same function symbol for that function. When the program is executed, will the loader be confused to determine from which library the function will be called. |
no, that system library is in a separate linker namespace. |
Thanks a lot. Good to know that. Will try our own library |
Description
I am building a program which requires protobuf. The protobuf libraries are taken from the prebuilt protobuf libraries from Android 8.1 (libprotobuf-cpp-lite.so & libprotobuf-cpp-full.so). When building the program with the NDK standalone toolchain (android-ndk-r19), I encountered undefined reference errors as follows.
./../lib/libpi_core_items.a(item_msg.pb.cc.o): In function
PI::proto::Mat::MergeFrom(PI::proto::Mat const&)': proto/item_msg.pb.cc:1524: undefined reference to
google::protobuf::internal::ArenaStringPtr::AssignWithDefault(std::__ndk1::basic_string<char, std::__ndk1::char_traits, std::__ndk1::allocator > const*, google::protobuf::internal::ArenaStringPtr)'proto/item_msg.pb.cc:1524: undefined reference to `google::protobuf::internal::ArenaStringPtr::AssignWithDefault(std::__ndk1::basic_string<char, std::__ndk1::char_traits, std::__ndk1::allocator > const*, google::protobuf::internal::ArenaStringPtr)'
The above function does exist in the protobuf libraries, however, the function symbol has a slight difference, e.g., the namespace of std::string is "std::__1::basic_string" instead of "std::__ndk1::basic_string" as shown below.
$ bin/aarch64-linux-android-objdump -CS libprotobuf-cpp-lite.so -T | grep AssignWithDefault
0000000000024180 g DF .text 0000000000000014 Base google::protobuf::internal::ArenaStringPtr::AssignWithDefault(std::__1::basic_string<char, std::__1::char_traits, std::__1::allocator > const*, google::protobuf::internal::ArenaStringPtr)
0000000000024180 <google::protobuf::internal::ArenaStringPtr::AssignWithDefault(std::__1::basic_string<char, std::__1::char_traits, std::__1::allocator > const*, google::protobuf::internal::ArenaStringPtr)@@base>:
Please advise why the NDK built program is not compatible with the Android prebuild libraries? In case of building a program which requires a library already existing in the Android tree, what will be the best way to link against it.
Environment Details
Not all of these will be relevant to every bug, but please provide as much
information as you can.
The text was updated successfully, but these errors were encountered: