gpt4 book ai didi

Android NDK 未定义对 google protobuf 的引用

转载 作者:行者123 更新时间:2023-11-29 01:05:02 24 4
gpt4 key购买 nike

我正在尝试制作一个使用 protobuf-lite 和 native 库的共享库。我四处搜索,但在使用 Windows 时找不到与 Android Studio 3、google protobuf-lite 和 Android NDK 相关的任何内容。我知道其他人必须尝试做我正在做的同样的事情,但我的细节在我读过的任何东西中都不明显。

我在跑:

  • Windows 10 64 位
  • Android Studio 3.0.1
  • Android NDK r16
  • protobuf-lite 版本 3.0.0
  • 并以 armeabi-v7a 为目标

我使用 DOCKER 文件创建了 libprotobuf-lite.so 我正在使用。码头文件:

  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

我正在编写一个能够从 Java 端使用的 C++ 库。我有一个 Android.mk 文件,我在 Android Studio 中使用它来构建 native 库。

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)'

这些错误出现在文件中:

  • osmformat.pb.cc
  • protobuf/wire_format_lite_inl.h
  • protobuf/arena.h
  • protobuf/generated_message_util.h
  • 和 fileformat.pb.cc

总共有 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

最佳答案

我发现导致 undefined reference 错误的东西在 .h 文件中未定义。我的印象是我只需要 .h 文件来使用 protobuf 库,但我需要随附的 .cc 文件来定义上述函数。我感谢所有试图提供帮助的人。希望我的经验可以用来帮助其他人。

关于Android NDK 未定义对 google protobuf 的引用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47891313/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com