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

This is happening because you might not be compiling both files so it is unable to locate/link the declaration of that function.

try this

gcc headerfile.c mainfile.c

于 2013-04-25T05:24:27.823 回答