其他分享
首页 > 其他分享> > android ndk对方法的未定义引用

android ndk对方法的未定义引用

作者:互联网

嗨,很抱歉,我正在尝试编译一些静态类,即jsmn.c,json.c和buf.c,它们是我从https://github.com/alisdair/jsmn-example/downloads下载的jsmn json库的一部分.

我正在编译两个STATIC_LIBRARIES lib1和json_librrary.lib1具有依赖于json_library的本机代码,然后将两个库制作成一个共享库,其中包含
 gnustl_static和lib1

我的文件夹结构如下

jni / lib1 / ANdroid.mk

include $(CLEAR_VARS)
LOCAL_MODULE := json_library
LOCAL_SRC_FILES := /3rdParty/jsmn/json_library.a
LOCAL_SRC_FILES := /3rdParty/jsmn/jsmn.c /3rdParty/jsmn/buf.c /3rdParty/jsmn/log.c /3rdParty/jsmn/json.c 
LOCAL_C_INCLUDES := /3rdParty/jsmn/jsmn.h /3rdParty/jsmn/buf.h /3rdParty/jsmn/log.h /3rdParty/jsmn/json.h 
# Optional compiler flags.
LOCAL_LDLIBS   = -lz -lm
LOCAL_CFLAGS   = -Wall -pedantic -std=c99 -g
include $(BUILD_STATIC_LIBRARY)

  include $(CLEAR_VARS)
  # Module Name
  LOCAL_MODULE    := lib1
  LOCAL_STATIC_LIBRARIES := json_library
  ........
  .......
  ......
  include $(BUILD_STATIC_LIBRARY)

jni / Android.mk

# Here we give our module name
LOCAL_MODULE    := lib2
# list the static modules included here!!!
LOCAL_STATIC_LIBRARIES :=   gnustl_static  lib1 
....
include $(BUILD_SHARED_LIBRARY)

jni / Application.mk

APP_MODULES   :=  lib2
# Optimization for release
APP_OPTM := release
#Targets
APP_ABI := armeabi-v7a armeabi

所以在lib1内部,我有一个类,它从名为json_tokenise的json库中调用一个方法.

#include <string.h>
#include <stdio.h>
 #include <stdlib.h>
 #include <jsmn/jsmn.h>
#include <jsmn/json.h>
#include <jsmn/buf.h>

jsmntok_t *tokens=json_tokenise((char *)data);

typedef enum {
START,
WRAPPER,
MESSAGE,
ROUTE,
OBJECT,
ARRAY,
SKIP,
STOP
}parse_state;

我收到以下错误

undefined reference to `json_tokenise(char*)'
collect2: ld returned 1 exit status
make: *** [obj/local/armeabi-v7a/lib2.so] Error 1

**** Build Finished ****

当我查看[obj / local / armeabi-v7a /
正在为armabi-v7生成libjson_library.a liblib1.a libgnustl_static.a,并且由于错误而无法生成lib2.

请帮助或指导我哪里出了问题我已经花了两天时间,但我还是NDK的新手.

解决方法:

您应该修复jni / lib1 / Android.mk文件:

LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := json_library
LOCAL_SRC_FILES := 3rdParty/jsmn/jsmn.c 3rdParty/jsmn/buf.c 3rdParty/jsmn/log.c 3rdParty/jsmn/json.c 
LOCAL_C_INCLUDES := $(LOCAL_PATH)/3rdParty/jsmn
# Optional compiler flags.
LOCAL_LDLIBS   = -lz -lm
LOCAL_CFLAGS   = -Wall -pedantic -std=c99 -g
include $(BUILD_STATIC_LIBRARY)

如果之后仍然遇到问题,请在命令行上使用参数V = 1运行ndk-build,并发布此版本的完整输出以及所有Android.mk文件的完整内容.

标签:android-ndk,static-libraries,undefined-reference,android-ndk-r7,android
来源: https://codeday.me/bug/20191031/1977935.html