3

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

我正在编译两个 STATIC_LIBRARIES lib1 和 json_library.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/应用程序.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/ 内部时,我可以看到 libjson_library.a liblib1.a libgnustl_static.a正在为 armabi-v7 生成,并且由于错误而无法生成 lib2。

请帮助或指导我哪里出错了我花了两天时间做这件事,我是 NDK 的新手。

4

2 回答 2

4

你应该修复你的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)

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

于 2012-10-27T02:36:04.290 回答
0

我遇到了类似的问题。json_library.a应该包含在预构建静态库模块中。这应该针对所需的平台进行编译。

include $(CLEAR_VARS)
LOCAL_MODULE := json_core
LOCAL_SRC_FILES := /3rdParty/jsmn/json_library.a
include $(PREBUILD_STATIC_LIBRARY)

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 := /3rdParty/jsmn/

最后,需要指定json_library模块依赖于json_core(prebuilt library) 。

LOCAL_STATIC_LIBRARIES := json_core 
# Optional compiler flags.
LOCAL_LDLIBS   = -lz -lm
LOCAL_CFLAGS   = -Wall -pedantic -std=c99 -g
include $(BUILD_STATIC_LIBRARY)

通过这种方式,链接器知道在哪里可以找到每个模块的所有方法定义。

于 2016-01-19T18:44:58.097 回答