7

本教程

看到我有一个名为 as 的预构建静态库stackoverflow.a ,它有stackoverflow.h

现在我想使用该静态库的功能

ndk_demo.c //那个教程有这个文件

对于里面ndk_demo.c我已经添加了

#include 'stackoverflow.h'  

编辑

inside `android-ndk-r7c`
         |
        apps
         |
        ndk_demo
         |
     -----------------
     |               |
   project          Application.mk
     |
--------------------
|                   |
all other           |
folder             jni
                    |  
-------------------------------------------------------------------
  |               |                     |          |              |
ndk_demo.c      stackoverflow.h        lib    com_marakana       Android.mk
                                        |      _NativeLib.h
                                        |
                             --------------------
                             |                   |
                          Android.mk          libstackoverflow.a

现在应用程序.mk

APP_PROJECT_PATH := $(call my-dir)/project
APP_MODULES      := ndk_demo stackover

现在jni/Android.mk

include $(call all-subdir-makefiles)
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE    := ndk_demo
LOCAL_SRC_FILES := ndk_demo.c
LOCAL_STATIC_LIBRARIES := stackover
include $(BUILD_SHARED_LIBRARY)

现在jni/lib/Android.mk

   LOCAL_PATH := $(call my-dir)
   include $(CLEAR_VARS)
   LOCAL_MODULE := stackover
   LOCAL_SRC_FILES := libstackoverflow.a
   include $(PREBUILT_STATIC_LIBRARY)
   LOCAL_PATH := $(call my-dir)

现在从android-ndk-r7c我运行的目录

make APP=ndk_demo

它向我显示错误

Android NDK: Building for application 'ndk_demo'    
make: *** No rule to make target `build/core/ndk_demo.c', needed by `out/apps/ndk_demo/armeabi/objs/ndk_demo/ndk_demo.o'.  Stop.

为什么发生这种情况我没有得到?

如果我评论

#include $(call all-subdir-makefiles)

从那时jni/Android.mk起它显示以下错误

Android NDK: Building for application 'ndk_demo'    
Compile thumb  : ndk_demo <= ndk_demo.c
SharedLibrary  : libndk_demo.so
./out/apps/ndk_demo/armeabi/objs/ndk_demo/ndk_demo.o: In function `Java_com_marakana_NativeLib_hello':
/home/jeegar/android-ndk-r7c/apps/ndk_demo/project/jni/ndk_demo.c:10: undefined reference to `stackoverflowInit'
collect2: ld returned 1 exit status
make: *** [out/apps/ndk_demo/armeabi/libndk_demo.so] Error 1
4

1 回答 1

6

当你得到“make: * No rule to make target `something.c'”时,它只是意味着它找不到文件。

我有点困惑你为什么要这样组织你的项目,但如果我要构建你的项目,我会这样做:

(doesn't matter which directory)
|
-->(ndk_demo)
-->-->(jni)
-->-->-->Application.mk
-->-->-->Android.mk
-->-->-->com_marakana_NativeLib.h
-->-->-->ndk_demo.c
-->-->(stackoverflow)
-->-->-->stackoverflow.h
-->-->-->libstackoverflow.a

然后我会使用以下makefile:

安卓.mk:

LOCAL_PATH := $(call my-dir)

### include stackoverflow as a prebuilt lib ###

include $(CLEAR_VARS)

LOCAL_MODULE            := stackoverflow-prebuilt
LOCAL_SRC_FILES         := ../stackoverflow/libstackoverflow.a
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/../stackoverflow

include $(PREBUILT_STATIC_LIBRARY)

### build your ndk lib ###

include $(CLEAR_VARS)

LOCAL_MODULE := ndk_demo
LOCAL_C_INCLUDES := $(LOCAL_PATH) \
                    $(LOCAL_PATH)/../stackoverflow
LOCAL_SRC_FILES := ndk_demo.c

LOCAL_LDLIBS := -llog
LOCAL_STATIC_LIBRARIES := stackoverflow-prebuilt

include $(BUILD_SHARED_LIBRARY)

以及以下内容:

应用程序.mk:

APP_MODULES := ndk_demo
APP_PLATFORM := android-8

最后,我将导航到目录 (ndk_demo) 并运行 ndk-build。

ndk-build 是 android 的构建工具。你应该使用它。可以在以下位置找到:

(AndroidSDK)/(NDK)/ndk-build

如果您使用的是 Windows,则必须在控制台中输入 ndk-build 的完整路径,或者在尝试运行之前将环境变量添加到系统中。

http://www.windows7hacker.com/index.php/2010/05/how-to-addedit-environment-variables-in-windows-7/

于 2012-04-13T02:21:02.640 回答