[英]NDK call function from native code
I am trying to call a simple connection function from native C code using the NDK and JNI. 我正在尝试使用NDK和JNI从本机C代码调用一个简单的连接函数。 The following is my code:
以下是我的代码:
C code - returns a value C代码-返回值
freerdp_ext_connect(const char *host, const char *username,
const char *pass, const char *domain,
int width, int height){}
Java code: Java代码:
#include <jni.h>
#include <stdio.h>
#include <freerdp/freerdp.h>
jstring Java_com_example_freerdpandroid_FreeRDPActivity_test(JNIEnv* env, jobject javaThis)
{
freerdp_ext_connect("10.123.123.12", "admin", "dsadsad", "", 600, 800);
return (*env)->NewStringUTF(env, "dsfsdf");
}
When trying to compile with cygwin it's giving me this error: 尝试使用cygwin进行编译时,出现此错误:
./obj/local/armeabi/objs/freerdp/freerdp.o: In function `Java_com_example_freerdpandroid_FreeRDPActivity_test':
C:\Users\stefan.scerri\workspace\freerdp/jni/freerdp.c:11: undefined reference to `freerdp_ext_connect'
collect2: ld returned 1 exit status
/cygdrive/c/android-ndk/android-ndk/build/core/build-binary.mk:378: recipe for target `obj/local/armeabi/libfreerdp.so' failed
make: *** [obj/local/armeabi/libfreerdp.so] Error 1
Any idea why this is so? 知道为什么会这样吗? I believe it is because of the return value of the C function, however I'm not sure, can someone kindly confirm.
我相信这是由于C函数的返回值引起的,但是我不确定是否可以有人确认。 Thanks in advance.
提前致谢。
Is the freerdp_ext_connect
in a compiled library, by any chance? freerdp_ext_connect
是否在编译的库中? If so, are you linking to that library when you build your NDK project? 如果是这样,那么在构建NDK项目时是否链接到该库? To link with a library, place the following into Android.mk:
要链接到库,请将以下内容放入Android.mk:
LOCAL_LDLIBS := -lfoo
And the linker will link against libfoo.a or libfoo.so, whichever is available. 链接器将链接到libfoo.a或libfoo.so(以可用的为准)。
If freerdp_ext_connect
is in a source file - are you compiling that source file? 如果
freerdp_ext_connect
在源文件中-您是否正在编译该源文件? The source file must be listed under LOCAL_SRC_FILES
in Android.mk. 源文件必须在Android.mk中的
LOCAL_SRC_FILES
下列出。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.