我正在尝试创建一个使用protobuf-lite和本机库的共享库。我一直在搜索,在使用Windows时我找不到任何与Android Studio 3,google protobuf-lite和Android NDK相关的内容。我知道其他人不得不尝试做我正在做的同样的事情,但我的具体内容在我读过的任何内容中都不明显。
我正在跑步:
我使用DOCKER文件来创建libprotobuf-lite.so我正在使用。 DOCKER文件:
FROM debian:stretch
ENV ANDROID_NDK_HOME /build/android-ndk
ENV ANDROID_NDK_VERSION=r16
RUN set -e -x && \
apt-get update && \
apt-get install -y \
unzip \
wget
#ADD android-ndk-${ANDROID_NDK_VERSION}-linux-x86_32.zip /build/android-
ndk.zip
RUN set -e -x && \
mkdir /build && \
cd /build && \
wget -q https://dl.google.com/android/repository/android-
ndk-${ANDROID_NDK_VERSION}-linux-x86_32.zip -O android-ndk.zip && \
unzip -q android-ndk.zip && \
mv ./android-ndk-${ANDROID_NDK_VERSION} ${ANDROID_NDK_HOME} && \
rm android-ndk.zip
#ADD protobuf-cpp-3.0.0.zip /build/protobuf.zip
RUN set -e -x && \
cd /build && \
wget -q
https://github.com/google/protobuf/releases/download/v3.0.0/protobuf-cpp-
3.0.0.zip -O protobuf-src.zip && \
unzip protobuf-src.zip && \
mv protobuf-3.0.0 protobuf && \
rm protobuf-src.zip
RUN set -e -x && \
cd /build && \
wget -q
https://github.com/google/protobuf/releases/download/v3.0.0/protoc-3.0.0-
linux-x86_32.zip -O protoc.zip && \
mkdir protoc && \
cd protoc && \
unzip ../protoc.zip && \
cd .. && \
rm protoc.zip
RUN set -e -x && \
apt-get update && \
apt-get install -y \
# protobuf compile
autoconf \
automake \
libtool \
curl \
make \
g++ \
# additional compile not in readme
libncurses5-dev \
# make_standalone_toolchain
python \
# util
nano
RUN /build/android-ndk/build/tools/make_standalone_toolchain.py \
--arch arm \
--install-dir /build/android-arm
ADD build.sh /build
WORKDIR /build/protobuf
CMD /bin/bash
我正在编写一个c ++库,可以从java端使用。我有一个Android.mk文件,我在Android Studio中使用它来构建本机库。
Android.mk文件:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := protobuf-lite
LOCAL_SRC_FILES := libprotobuf-lite.so
LOCAL_CFLAGS := -std=c++11
include $(PREBUILT_SHARED_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := native-lib
LOCAL_SRC_FILES := native-lib.cpp \
BeaconSearchResult.cpp \
fileformat.pb.cc \
Geopoint.cpp \
Location.cpp \
osmformat.pb.cc \
osmpbf.cpp \
OSMPBFread.cpp \
OSMPOISearch.cpp \
POI.cpp \
TARGET_ARCH_ABI := armeabi-v7a
LOCAL_LDFLAGS := -lz -llog
LOCAL_SHARED_LIBRARIES := libprotobuf-lite
LOCAL_CPP_FEATURES := rtti
LOCAL_CFLAGS := -std=c++11
include $(BUILD_SHARED_LIBRARY)
我得到的错误是:
Error:(511) undefined reference to 'google::protobuf::internal::MergeFromFail(char const*, int)'
Error:(521) undefined reference to 'google::protobuf::internal::ArenaStringPtr::AssignWithDefault(std::__ndk1::basic_string<char, std::__ndk1::char_traits<char>, std::__ndk1::allocator<char> > const*, google::protobuf::internal::ArenaStringPtr)'
Error:(237) undefined reference to 'google::protobuf::io::LazyStringOutputStream::LazyStringOutputStream(google::protobuf::ResultCallback<std::__ndk1::basic_string<char, std::__ndk1::char_traits<char>, std::__ndk1::allocator<char> >*>*)'
Error:(377) undefined reference to 'google::protobuf::io::LazyStringOutputStream::~LazyStringOutputStream()'
Error:(390) undefined reference to 'google::protobuf::internal::WireFormatLite::WriteString(int, std::__ndk1::basic_string<char, std::__ndk1::char_traits<char>, std::__ndk1::all
Error:(817) undefined reference to 'google::protobuf::io::CodedOutputStream::VarintSize64(unsigned long long)'
Error:(830) undefined reference to 'google::protobuf::Arena::AddListNode(void*, void (*)(void*))'
Error:(640) undefined reference to 'google::protobuf::Arena::AllocateAligned(std::type_info const*, unsigned int)'
这些错误出现在文件中:
总共有49个错误。我知道我正在做的事情必须是正确的,因为如果我在Android.mk中取出LOCAL_SHARED_LIBRARIES的行,它会给我159个错误。我在我的智慧结束,我真的可以用一些新鲜的眼睛。如果您需要更多信息,请告诉我们。
编辑:我在gradle控制台中发现了一些错误信息:
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:externalNativeBuildDebug'.
> Build command failed.
Error while executing process C:\Users\jkarr\AppData\Local\Android\Sdk\ndk-bundle\ndk-build.cmd with arguments {NDK_PROJECT_PATH=null APP_BUILD_SCRIPT=C:\Users\jkarr\Hellocmake\app\src\main\jni\armeabi-v7a\Android.mk NDK_APPLICATION_MK=C:\Users\jkarr\Hellocmake\app\src\main\jni\armeabi-v7a\Application.mk APP_ABI=armeabi-v7a NDK_ALL_ABIS=armeabi-v7a NDK_DEBUG=1 APP_PLATFORM=android-15 NDK_OUT=C:/Users/jkarr/Hellocmake/app/build/intermediates/ndkBuild/debug/obj NDK_LIBS_OUT=C:\Users\jkarr\Hellocmake\app\build\intermediates\ndkBuild\debug\lib C:/Users/jkarr/Hellocmake/app/build/intermediates/ndkBuild/debug/obj/local/armeabi-v7a/libnative-lib.so}
Android NDK: WARNING: Unsupported source file extensions in C:\Users\jkarr\Hellocmake\app\src\main\jni\armeabi-v7a\Android.mk for module native-lib
Android NDK: TARGET_ARCH_ABI := armeabi-v7a
[armeabi-v7a] SharedLibrary : libnative-lib.so
C:/Users/jkarr/Hellocmake/app/src/main/jni/armeabi-v7a/osmformat.pb.cc:512: error: undefined reference to 'google::protobuf::internal::MergeFromFail(char const*, int)'
C:/Users/jkarr/Hellocmake/app/src/main/jni/armeabi-v7a/osmformat.pb.cc:522: error: undefined reference to 'google::protobuf::internal::ArenaStringPtr::AssignWithDefault(std::__ndk1::basic_string<char, std::__ndk1::char_traits<char>, std::__ndk1::allocator<char> > const*, google::protobuf::internal::ArenaStringPtr)'
C:/Users/jkarr/Hellocmake/app/src/main/jni/armeabi-v7a/osmformat.pb.cc:526: error: undefined reference to 'google::protobuf::internal::ArenaStringPtr::AssignWithDefault(std::__ndk1::basic_string<char, std::__ndk1::char_traits<char>, std::__ndk1::allocator<char> > const*, google::protobuf::internal::ArenaStringPtr)'
C:/Users/jkarr/Hellocmake/app/src/main/jni/armeabi-v7a/osmformat.pb.cc:536: error: undefined reference to 'google::protobuf::internal::ArenaStringPtr::AssignWithDefault(std::__ndk1::basic_string<char, std::__ndk1::char_traits<char>, std::__ndk1::allocator<char> > const*, google::protobuf::internal::ArenaStringPtr)'
C:/Users/jkarr/Hellocmake/app/src/main/jni/armeabi-v7a/google/include/protobuf/arena.h:830: error: undefined reference to 'google::protobuf::Arena::AddListNode(void*, void (*)(void*))'
C:/Users/jkarr/Hellocmake/app/src/main/jni/armeabi-v7a/osmformat.pb.cc:238: error: undefined reference to 'google::protobuf::io::LazyStringOutputStream::LazyStringOutputStream(google::protobuf::ResultCallback<std::__ndk1::basic_string<char, std::__ndk1::char_traits<char>, std::__ndk1::allocator<char> >*>*)'
C:/Users/jkarr/Hellocmake/app/src/main/jni/armeabi-v7a/osmformat.pb.cc:378: error: undefined reference to 'google::protobuf::io::LazyStringOutputStream::~LazyStringOutputStream()'
C:/Users/jkarr/Hellocmake/app/src/main/jni/armeabi-v7a/osmformat.pb.cc:391: error: undefined reference to 'google::protobuf::internal::WireFormatLite::WriteString(int, std::__ndk1::basic_string<char, std::__ndk1::char_traits<char>, std::__ndk1::allocator<char> > const&, google::protobuf::io::CodedOutputStream*)'
C:/Users/jkarr/Hellocmake/app/src/main/jni/armeabi-v7a/osmformat.pb.cc:397: error: undefined reference to 'google::protobuf::internal::WireFormatLite::WriteString(int, std::__ndk1::basic_string<char, std::__ndk1::char_traits<char>, std::__ndk1::allocator<char> > const&, google::protobuf::io::CodedOutputStream*)'
C:/Users/jkarr/Hellocmake/app/src/main/jni/armeabi-v7a/osmformat.pb.cc:403: error: undefined reference to 'google::protobuf::internal::WireFormatLite::WriteStringMaybeAliased(int, std::__ndk1::basic_string<char, std::__ndk1::char_traits<char>, std::__ndk1::allocator<char> > const&, google::protobuf::io::CodedOutputStream*)'
C:/Users/jkarr/Hellocmake/app/src/main/jni/armeabi-v7a/osmformat.pb.cc:409: error: undefined reference to 'google::protobuf::internal::WireFormatLite::WriteStringMaybeAliased(int, std::__ndk1::basic_string<char, std::__ndk1::char_traits<char>, std::__ndk1::allocator<char> > const&, google::protobuf::io::CodedOutputStream*)'
C:/Users/jkarr/Hellocmake/app/src/main/jni/armeabi-v7a/osmformat.pb.cc:425: error: undefined reference to 'google::protobuf::internal::WireFormatLite::WriteStringMaybeAliased(int, std::__ndk1::basic_string<char, std::__ndk1::char_traits<char>, std::__ndk1::allocator<char> > const&, google::protobuf::io::CodedOutputStream*)'
C:/Users/jkarr/Hellocmake/app/src/main/jni/armeabi-v7a/google/include/protobuf/wire_format_lite_inl.h:817: error: undefined reference to 'google::protobuf::io::CodedOutputStream::VarintSize64(unsigned long long)'
C:/Users/jkarr/Hellocmake/app/src/main/jni/armeabi-v7a/osmformat.pb.cc:1267: error: undefined reference to 'google::protobuf::internal::MergeFromFail(char const*, int)'
C:/Users/jkarr/Hellocmake/app/src/main/jni/armeabi-v7a/google/include/protobuf/arena.h:830: error: undefined reference to 'google::protobuf::Arena::AddListNode(void*, void (*)(void*))'
C:/Users/jkarr/Hellocmake/app/src/main/jni/armeabi-v7a/osmformat.pb.cc:1069: error: undefined reference to 'google::protobuf::io::LazyStringOutputStream::LazyStringOutputStream(google::protobuf::ResultCallback<std::__ndk1::basic_string<char, std::__ndk1::char_traits<char>, std::__ndk1::allocator<char> >*>*)'
C:/Users/jkarr/Hellocmake/app/src/main/jni/armeabi-v7a/osmformat.pb.cc:1159: error: undefined reference to 'google::protobuf::io::LazyStringOutputStream::~LazyStringOutputStream()'
C:/Users/jkarr/Hellocmake/app/src/main/jni/armeabi-v7a/google/include/protobuf/wire_format_lite_inl.h:829: error: undefined reference to 'google::protobuf::io::CodedOutputStream::VarintSize64(unsigned long long)'
C:/Users/jkarr/Hellocmake/app/src/main/jni/armeabi-v7a/osmformat.pb.cc:1760: error: undefined reference to 'google::protobuf::internal::MergeFromFail(char const*, int)'
C:/Users/jkarr/Hellocmake/app/src/main/jni/armeabi-v7a/google/include/protobuf/arena.h:830: error: undefined reference to 'google::protobuf::Arena::AddListNode(void*, void (*)(void*))'
C:/Users/jkarr/Hellocmake/app/src/main/jni/armeabi-v7a/osmformat.pb.cc:1534: error: undefined reference to 'google::protobuf::io::LazyStringOutputStream::LazyStringOutputStream(google::protobuf::ResultCallback<std::__ndk1::basic_string<char, std::__ndk1::char_traits<char>, std::__ndk1::allocator<char> >*>*)'
C:/Users/jkarr/Hellocmake/app/src/main/jni/armeabi-v7a/osmformat.pb.cc:1654: error: undefined reference to 'google::protobuf::io::LazyStringOutputStream::~LazyStringOutputStream()'
C:/Users/jkarr/Hellocmake/app/src/main/jni/armeabi-v7a/osmformat.pb.cc:2712: error: undefined reference to 'google::protobuf::internal::MergeFromFail(char const*, int)'
C:/Users/jkarr/Hellocmake/app/src/main/jni/armeabi-v7a/google/include/protobuf/arena.h:830: error: undefined reference to 'google::protobuf::Arena::AddListNode(void*, void (*)(void*))'
C:/Users/jkarr/Hellocmake/app/src/main/jni/armeabi-v7a/osmformat.pb.cc:2104: error: undefined reference to 'google::protobuf::io::LazyStringOutputStream::LazyStringOutputStream(google::protobuf::ResultCallback<std::__ndk1::basic_string<char, std::__ndk1::char_traits<char>, std::__ndk1::allocator<char> >*>*)'
C:/Users/jkarr/Hellocmake/app/src/main/jni/armeabi-v7a/osmformat.pb.cc:2213: error: undefined reference to 'google::protobuf::io::LazyStringOutputStream::~LazyStringOutputStream()'
C:/Users/jkarr/Hellocmake/app/src/main/jni/armeabi-v7a/osmformat.pb.cc:2639: error: undefined reference to 'google::protobuf::internal::WireFormatLite::ReadBytes(google::protobuf::io::CodedInputStream*, std::__ndk1::basic_string<char, std::__ndk1::char_traits<char>, std::__ndk1::allocator<char> >*)'
C:/Users/jkarr/Hellocmake/app/src/main/jni/armeabi-v7a/osmformat.pb.cc:2676: error: undefined reference to 'google::protobuf::internal::WireFormatLite::WriteBytes(int, std::__ndk1::basic_string<char, std::__ndk1::char_traits<char>, std::__ndk1::allocator<char> > const&, google::protobuf::io::CodedOutputStream*)'
C:/Users/jkarr/Hellocmake/app/src/main/jni/armeabi-v7a/google/include/protobuf/wire_format_lite_inl.h:544: error: undefined reference to 'google::protobuf::io::CodedOutputStream::WriteVarint64(unsigned long long)'
C:/Users/jkarr/Hellocmake/app/src/main/jni/armeabi-v7a/google/include/protobuf/wire_format_lite_inl.h:544: error: undefined reference to 'google::protobuf::io::CodedOutputStream::WriteVarint64(unsigned long long)'
C:/Users/jkarr/Hellocmake/app/src/main/jni/armeabi-v7a/google/include/protobuf/wire_format_lite_inl.h:544: error: undefined reference to 'google::protobuf::io::CodedOutputStream::WriteVarint64(unsigned long long)'
C:/Users/jkarr/Hellocmake/app/src/main/jni/armeabi-v7a/google/include/protobuf/wire_format_lite_inl.h:544: error: undefined reference to 'google::protobuf::io::CodedOutputStream::WriteVarint64(unsigned long long)'
C:/Users/jkarr/Hellocmake/app/src/main/jni/armeabi-v7a/google/include/protobuf/arena.h:640: error: undefined reference to 'google::protobuf::Arena::AllocateAligned(std::type_info const*, unsigned int)'
C:/Users/jkarr/Hellocmake/app/src/main/jni/armeabi-v7a/google/include/protobuf/arena.h:640: error: undefined reference to 'google::protobuf::Arena::AllocateAligned(std::type_info const*, unsigned int)'
C:/Users/jkarr/Hellocmake/app/src/main/jni/armeabi-v7a/google/include/protobuf/arena.h:640: error: undefined reference to 'google::protobuf::Arena::AllocateAligned(std::type_info const*, unsigned int)'
C:/Users/jkarr/Hellocmake/app/src/main/jni/armeabi-v7a/google/include/protobuf/arena.h:640: error: undefined reference to 'google::protobuf::Arena::AllocateAligned(std::type_info const*, unsigned int)'
C:/Users/jkarr/Hellocmake/app/src/main/jni/armeabi-v7a/fileformat.pb.cc:372: error: undefined reference to 'google::protobuf::internal::ArenaStringPtr::AssignWithDefault(std::__ndk1::basic_string<char, std::__ndk1::char_traits<char>, std::__ndk1::allocator<char> > const*, google::protobuf::internal::ArenaStringPtr)'
C:/Users/jkarr/Hellocmake/app/src/main/jni/armeabi-v7a/google/include/protobuf/generated_message_util.h:87: error: undefined reference to 'google::protobuf::internal::empty_string_'
C:/Users/jkarr/Hellocmake/app/src/main/jni/armeabi-v7a/google/include/protobuf/generated_message_util.h:87: error: undefined reference to 'google::protobuf::internal::empty_string_'
C:/Users/jkarr/Hellocmake/app/src/main/jni/armeabi-v7a/fileformat.pb.cc:188: error: undefined reference to 'google::protobuf::internal::WireFormatLite::ReadBytes(google::protobuf::io::CodedInputStream*, std::__ndk1::basic_string<char, std::__ndk1::char_traits<char>, std::__ndk1::allocator<char> >*)'
C:/Users/jkarr/Hellocmake/app/src/main/jni/armeabi-v7a/fileformat.pb.cc:216: error: undefined reference to 'google::protobuf::internal::WireFormatLite::ReadBytes(google::protobuf::io::CodedInputStream*, std::__ndk1::basic_string<char, std::__ndk1::char_traits<char>, std::__ndk1::allocator<char> >*)'
C:/Users/jkarr/Hellocmake/app/src/main/jni/armeabi-v7a/fileformat.pb.cc:229: error: undefined reference to 'google::protobuf::internal::WireFormatLite::ReadBytes(google::protobuf::io::CodedInputStream*, std::__ndk1::basic_string<char, std::__ndk1::char_traits<char>, std::__ndk1::allocator<char> >*)'
C:/Users/jkarr/Hellocmake/app/src/main/jni/armeabi-v7a/fileformat.pb.cc:278: error: undefined reference to 'google::protobuf::internal::WireFormatLite::WriteBytesMaybeAliased(int, std::__ndk1::basic_string<char, std::__ndk1::char_traits<char>, std::__ndk1::allocator<char> > const&, google::protobuf::io::CodedOutputStream*)'
C:/Users/jkarr/Hellocmake/app/src/main/jni/armeabi-v7a/fileformat.pb.cc:289: error: undefined reference to 'google::protobuf::internal::WireFormatLite::WriteBytesMaybeAliased(int, std::__ndk1::basic_string<char, std::__ndk1::char_traits<char>, std::__ndk1::allocator<char> > const&, google::protobuf::io::CodedOutputStream*)'
C:/Users/jkarr/Hellocmake/app/src/main/jni/armeabi-v7a/fileformat.pb.cc:295: error: undefined reference to 'google::protobuf::internal::WireFormatLite::WriteBytesMaybeAliased(int, std::__ndk1::basic_string<char, std::__ndk1::char_traits<char>, std::__ndk1::allocator<char> > const&, google::protobuf::io::CodedOutputStream*)'
C:/Users/jkarr/Hellocmake/app/src/main/jni/armeabi-v7a/fileformat.pb.cc:301: error: undefined reference to 'google::protobuf::internal::WireFormatLite::WriteBytesMaybeAliased(int, std::__ndk1::basic_string<char, std::__ndk1::char_traits<char>, std::__ndk1::allocator<char> > const&, google::protobuf::io::CodedOutputStream*)'
C:/Users/jkarr/Hellocmake/app/src/main/jni/armeabi-v7a/fileformat.pb.cc:852: error: undefined reference to 'google::protobuf::internal::WireFormatLite::WriteStringMaybeAliased(int, std::__ndk1::basic_string<char, std::__ndk1::char_traits<char>, std::__ndk1::allocator<char> > const&, google::protobuf::io::CodedOutputStream*)'
C:/Users/jkarr/Hellocmake/app/src/main/jni/armeabi-v7a/google/include/protobuf/io/coded_stream.h:1232: error: undefined reference to 'google::protobuf::io::CodedOutputStream::VarintSize32Fallback(unsigned int)'
clang++.exe: error: linker command failed with exit code 1 (use -v to see invocation)
make: ***[C:/Users/jkarr/Hellocmake/app/build/intermediates/ndkBuild/debug/obj/local/armeabi-v7a/libnative-lib.so] Error 1
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
* Get more help at https://help.gradle.org
BUILD FAILED in 2s
答案 0 :(得分:1)
我发现导致未定义引用错误的内容在.h文件中未定义。我的印象是我只需要.h文件来使用protobuf库,但我需要附带的.cc文件来定义所述函数。我感谢所有试图提供帮助的人。希望我的经验能够用来帮助别人。