gpt4 book ai didi

android - 在android ndk中链接静态库

转载 作者:塔克拉玛干 更新时间:2023-11-02 18:56:55 25 4
gpt4 key购买 nike

我正在尝试从 http://developer.nvidia.com/tegra-resources 编译 nvfile 库,在android ndk示例中,libs文件夹。不管怎样,因为我真的不需要整套库,所以我拿出了我需要的那个,似乎是它的依赖项。这是用于编译它们的 Android.mk 文件。

include $(CLEAR_VARS)
LOCAL_MODULE := nvthread
LOCAL_CFLAGS := -Wall -g
LOCAL_LDFLAGS := -Wl,-Map,xxx.map
LOCAL_SRC_FILES := nv/nv_thread/nv_thread.c
LOCAL_C_INCLUDES := nv

include $(BUILD_STATIC_LIBRARY)


include $(CLEAR_VARS)
LOCAL_MODULE := nvfile
LOCAL_CFLAGS := -Wall -g
LOCAL_LDFLAGS := -Wl,-Map,xxx.map
LOCAL_SRC_FILES := nv/nv_file/nv_file.c
LOCAL_C_INCLUDES := nv
LOCAL_STATIC_LIBRARIES := nvthread nvapkfile

include $(BUILD_STATIC_LIBRARY)


include $(CLEAR_VARS)
LOCAL_MODULE := nvapkfile
LOCAL_CFLAGS := -Wall -g
LOCAL_LDFLAGS := -Wl,-Map,xxx.map
LOCAL_SRC_FILES := nv/nv_apk_file/nv_apk_file.c
LOCAL_C_INCLUDES := nv
LOCAL_STATIC_LIBRARIES := nvthread

include $(BUILD_STATIC_LIBRARY)

nvapkfile 库似乎能够很好地与 nvthread 链接,但 nvfile 库似乎根本不想链接到 nvapkfile 库。源代码中的包含文件工作正常,只是每当我尝试编译它时,我都会得到一个 undefined reference 。这是输出示例:

/home/leif/MarbleMachine/android/obj/local/armeabi/libnvfile.a(nv_file.o): In function `NvFInit':
/home/leif/MarbleMachine/android/jni/nv/nv_file/nv_file.c:49: undefined reference to `NvAPKInit'
/home/leif/MarbleMachine/android/obj/local/armeabi/libnvfile.a(nv_file.o): In function `NvFOpen':
/home/leif/MarbleMachine/android/jni/nv/nv_file/nv_file.c:77: undefined reference to `NvAPKOpen'
/home/leif/MarbleMachine/android/jni/nv/nv_file/nv_file.c:82: undefined reference to `NvAPKOpen'
/home/leif/MarbleMachine/android/obj/local/armeabi/libnvfile.a(nv_file.o): In function `NvFClose':
/home/leif/MarbleMachine/android/jni/nv/nv_file/nv_file.c:97: undefined reference to `NvAPKClose'
/home/leif/MarbleMachine/android/obj/local/armeabi/libnvfile.a(nv_file.o): In function `NvFGetc':
/home/leif/MarbleMachine/android/jni/nv/nv_file/nv_file.c:118: undefined reference to `NvAPKGetc'
/home/leif/MarbleMachine/android/obj/local/armeabi/libnvfile.a(nv_file.o): In function `NvFGets':
/home/leif/MarbleMachine/android/jni/nv/nv_file/nv_file.c:133: undefined reference to `NvAPKGets'
/home/leif/MarbleMachine/android/obj/local/armeabi/libnvfile.a(nv_file.o): In function `NvFSize':
/home/leif/MarbleMachine/android/jni/nv/nv_file/nv_file.c:148: undefined reference to `NvAPKSize'
/home/leif/MarbleMachine/android/obj/local/armeabi/libnvfile.a(nv_file.o): In function `NvFSeek':
/home/leif/MarbleMachine/android/jni/nv/nv_file/nv_file.c:171: undefined reference to `NvAPKSeek'
/home/leif/MarbleMachine/android/obj/local/armeabi/libnvfile.a(nv_file.o): In function `NvFTell':
/home/leif/MarbleMachine/android/jni/nv/nv_file/nv_file.c:186: undefined reference to `NvAPKTell'
/home/leif/MarbleMachine/android/obj/local/armeabi/libnvfile.a(nv_file.o): In function `NvFRead':
/home/leif/MarbleMachine/android/jni/nv/nv_file/nv_file.c:201: undefined reference to `NvAPKRead'
/home/leif/MarbleMachine/android/obj/local/armeabi/libnvfile.a(nv_file.o): In function `NvFEOF':
/home/leif/MarbleMachine/android/jni/nv/nv_file/nv_file.c:216: undefined reference to `NvAPKEOF'

我根本没有修改实际的 c 或 h 文件。但作为引用,这里是有问题的相关 C 文件的一部分:

#include "nv_file.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#ifdef ANDROID
#include "../nv_apk_file/nv_apk_file.h"
#define SUPPORT_APK 1
#include <unistd.h>
#endif

//...

void NvFInit()
{
#ifdef SUPPORT_APK
NvAPKInit();
#endif
}

这是 nv_file.c 的第 22-32 行和第 46-51 行

如您所见, header 已包含在内,但未链接。有谁知道我在这里缺少什么?谢谢。

最佳答案

Ugg..看来我只是按错了顺序。转动这一行(在 nvfile 模块中):

LOCAL_STATIC_LIBRARIES := nvthread nvapkfile

LOCAL_STATIC_LIBRARIES := nvapkfile nvthread

让它编译得很好。任何人都可以确认您在 LOCAL_STATIC_LIBRARIES 中列出库的顺序很重要吗?谢谢。

关于android - 在android ndk中链接静态库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6118355/

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