0

ダイナミック リンク ライブラリを使用してネイティブ C プログラムを作成したいので、これらのファイルを Android/development/hello/ に配置します: hello.c、myprint.h、myprint.c、main() は hello.c にあり、 Android.mk は次のとおりです。

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)
LOCAL_MODULE := myprint
LOCAL_SRC_FILES := myprint.c
include $(BUILD_SHARED_LIBRARY)

include $(CLEAR_VARS)
LOCAL_MODULE := helloworld
LOCAL_SRC_FILES := hello.c
LOCAL_SHARED_LIBRARIES := myprint
include $(BUILD_EXECUTABLE)

次に、helloworld を作成します。出力情報は次のとおりです。

target thumb C: helloworld <= development/hello/hello.c
target thumb C: myprint <= development/hello/myprint.c
target SharedLib: myprint (out/target/product/generic/obj/SHARED_LIBRARIES/myprint_intermediates/LINKED/myprint.so)
target Symbolic: myprint (out/target/product/generic/symbols/system/lib/myprint.so)
target Strip: myprint (out/target/product/generic/obj/lib/myprint.so)
target Executable: helloworld (out/target/product/generic/obj/EXECUTABLES/helloworld_intermediates/LINKED/helloworld)
/home/neil/dev/google_422/prebuilts/gcc/linux-x86/arm/arm-linux-androideabi-4.7/bin/../lib/gcc/arm-linux-androideabi/4.7/../../../../arm-linux-androideabi/bin/ld: error: cannot find -lmyprint.so
development/hello/hello.c:5: error: undefined reference to 'myprint'
collect2: error: ld returned 1 exit status

私を助けてください...

そして、私のネイティブコードは次のとおりです。

// hello.c
#include "myprint.h"
int main()
{
    myprint();
    return 0;
}

// myprint.h
void myprint();

// myprint.c
#include <stdio.h>
void myprint()
{
    printf("myprint...\n");
}
4

1 に答える 1

0

これは、両方のファイルをコンパイルしていない可能性があるため、その関数の宣言を見つけたりリンクしたりできないために発生しています。

これを試して

gcc headerfile.c mainfile.c

于 2013-04-25T05:24:27.823 に答える