gpt4 book ai didi

依赖于另一个模块的 Android NDK 模块

转载 作者:太空宇宙 更新时间:2023-11-03 13:24:19 24 4
gpt4 key购买 nike

我有一个使用 Android NDK 编写的 android 项目。在项目中,我使用了两个预构建的共享库(GpkgSDK 和 spatialite)并构建了另外两个共享库(WFSHelpers 和 com_example_gpkgviewer_jni_WKTConverter)。与应用程序的 Java 级别交互的唯一库是 com_example_gpkgviewer_jni_WKTConverter 库。

库之间的依赖关系如下图所示:

  • WFSHelpers 依赖于 GpkgSDK 和 spatialite
  • com_example_gpkgviewer_jni_WKTConverter 依赖于 WFSHelpers

我遇到的问题是,当我尝试运行 ndk-build 时,我在尝试构建 com_example_gpkgviewer_jni_WKTConverter 库时收到大量 undefined reference 。其他库已成功构建。我通常解决这些 undefined reference 的方法是在我的 com_example_gpkgviewer_jni_WKTConverter 模块定义中包含以下内容:

LOCAL_SHARED_LIBRARY := WFSHelpers

我不确定我是否还需要像这样包含 WFSHelpers 所依赖的库:

LOCAL_SHARED_LIBRARY := WFSHelpers GpkgSDK spatialite

我也像这样以不同的顺序尝试过它们,但它似乎并没有解决我的问题:

  • LOCAL_SHARED_LIBRARY := GpkgSDK spatialite WFSHelpers

我的 Application.mk 包含在下面:

NDK_TOOLCHAIN_VERSION := 4.8
# APP_STL := stlport_shared --> does not seem to contain C++11 features
APP_STL := gnustl_shared

# Enable c++11 extentions in source code
APP_CPPFLAGS += -std=c++11
APP_CPPFLAGS += -frtti
APP_CPPFLAGS += -fexceptions

APP_MODULES := GpkgSDK spatialite WFSHelpers com_example_gpkgviewer_jni_WKTConverter

APP_ABI := armeabi armeabi-v7a

我的Android.mk如下图:

LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := GpkgSDK
LOCAL_SRC_FILES := libMP.so
LOCAL_EXPORT_C_INCLUDES := \
$(LOCAL_PATH)/include \
include $(PREBUILT_SHARED_LIBRARY)

include $(CLEAR_VARS)
LOCAL_MODULE := spatialite
LOCAL_SRC_FILES := spatialamal/prebuilt/$(TARGET_ARCH_ABI)/libspatialite.so
LOCAL_EXPORT_C_INCLUDES := spatialamal/headers/spatialite \
spatialamal/headers
include $(PREBUILT_SHARED_LIBRARY)

include $(CLEAR_VARS)
LOCAL_MODULE := WFSHelpers
LOCAL_LDLIBS := -L$(SYSROOT)/usr/lib -llog
LOCAL_SRC_FILES := \
GPKGReader/Debug.h \
GPKGReader/DLLExport.h \
GPKGReader/DBQueryResult.cpp \
GPKGReader/GeoPackageDB.cpp \
GPKGReader/GPKGReader.cpp \
GPKGReader/order32.h \
GPKGReader/SpecDefinitions.h \
GPKGReader/WKBGenericGeometry.cpp \
GPKGReader/WKBLineString.cpp \
GPKGReader/WKBMultiLineString.cpp \
GPKGReader/WKBMultiPolygon.cpp \
GPKGReader/WKBPoint.cpp \
GPKGReader/WKBPolygon.cpp \
GPKGDataLayer/GPKGDataLayer.cpp
LOCAL_SHARED_LIBRARIES := GpkgSDK spatialite
include $(BUILD_SHARED_LIBRARY)

include $(CLEAR_VARS)
LOCAL_LDLIBS := -L$(SYSROOT)/usr/lib -llog
LOCAL_MODULE := com_example_gpkgviewer_jni_WKTConverter
LOCAL_SRC_FILES := com_example_gpkgviewer_jni_WKTConverter.cpp
LOCAL_SHARED_LIBRARY := WFSHelpers GpkgSDK spatialite
include $(BUILD_SHARED_LIBRARY)

我收到的 undefined reference 错误示例如下所示:

[armeabi] SharedLibrary  : libcom_example_gpkgviewer_jni_WKTConverter.so
jni/com_example_gpkgviewer_jni_WKTConverter.cpp:59: error: undefined reference
o 'WKBGenericGeometry::readInt32(unsigned char, unsigned char*, unsigned int)'
collect2.exe: error: ld returned 1 exit status
make.exe: *** [obj/local/armeabi/libcom_example_gpkgviewer_jni_WKTConverter.so]
Error 1

com_example_gpkgviewer_jni_WKTConverter.cpp 中导致此错误的代码行如下所示:

*id_arg = WKBGenericGeometry::readInt32(byte_order, &(bytes[4]), length - 4);

关于如何解决依赖关系的任何建议。

最佳答案

在尝试让它构建多年之后,我终于能够让它工作了。虽然,我不太确定有什么区别,所以欢迎任何可以阐明这一点的人这样做。我的问题是我依赖于其他库。文档说明如下:

LOCAL_SHARED_LIBRARIES
The list of shared libraries modules this module depends on at runtime. This is necessary at link time and to embed the corresponding information in the generated file.

LOCAL_LDLIBS
The list of additional linker flags to be used when building your shared library or executable. This is useful to pass the name of specific system libraries with the '-l' prefix. For example, the following will tell the linker to generate a module that links to /system/lib/libz.so at load time:

LOCAL_LDLIBS := -lz

See STABLE-APIS for the list of exposed system libraries you can linked against with this NDK release.
NOTE: This is ignored for static libraries, and ndk-build will print a warning if you define it in such a module.

因此在我的 Android.mk 文件中,我不得不使用 LOCAL_LDLIBS 而不是 LOCAL_SHARED_LIBRARIES 来指示依赖关系。

我新建的Android.mk如下图:

LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := GpkgSDK
LOCAL_SRC_FILES := libMP.so
LOCAL_EXPORT_C_INCLUDES := \
$(LOCAL_PATH)/include \
include $(PREBUILT_SHARED_LIBRARY)

include $(CLEAR_VARS)
LOCAL_MODULE := spatialite
LOCAL_SRC_FILES := spatialamal/prebuilt/$(TARGET_ARCH_ABI)/libspatialite.so
LOCAL_EXPORT_C_INCLUDES := spatialamal/headers/spatialite \
spatialamal/headers
include $(PREBUILT_SHARED_LIBRARY)

include $(CLEAR_VARS)
LOCAL_MODULE := WFSHelpers
LOCAL_SRC_FILES := \
GPKGReader/Debug.h \
GPKGReader/DLLExport.h \
GPKGReader/DBQueryResult.cpp \
GPKGReader/GeoPackageDB.cpp \
GPKGReader/GPKGReader.cpp \
GPKGReader/order32.h \
GPKGReader/SpecDefinitions.h \
GPKGReader/WKBGenericGeometry.cpp \
GPKGReader/WKBLineString.cpp \
GPKGReader/WKBMultiLineString.cpp \
GPKGReader/WKBMultiPolygon.cpp \
GPKGReader/WKBPoint.cpp \
GPKGReader/WKBPolygon.cpp \
GPKGDataLayer/GPKGDataLayer.cpp
LOCAL_LDLIBS := libs/$(TARGET_ARCH_ABI)/libGpkgSDK.so
LOCAL_LDLIBS += libs/$(TARGET_ARCH_ABI)/libspatialite.so
LOCAL_LDLIBS += -L$(SYSROOT)/usr/lib -llog
include $(BUILD_SHARED_LIBRARY)

include $(CLEAR_VARS)
LOCAL_MODULE := com_example_gpkgviewer_jni_WKTConverter
LOCAL_SRC_FILES := com_example_gpkgviewer_jni_WKTConverter.cpp
LOCAL_LDLIBS := libs/$(TARGET_ARCH_ABI)/libWFSHelpers.so
LOCAL_LDLIBS += libs/$(TARGET_ARCH_ABI)/libGpkgSDK.so
include $(BUILD_SHARED_LIBRARY)

我将暂时保留这个答案,因为我不完全确定 LOCAL_LDLIBS 和 LOCAL_SHARED_LIBRARIES 之间的区别是什么。如果有人可以向我提供解释,请提供。如果没有,我会在给它一些时间后将这个答案标记为已接受。谢谢!

关于依赖于另一个模块的 Android NDK 模块,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22503274/

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