在独立的本地库调用本地方法库 [英] Call native library method in independent native library

查看:147
本文介绍了在独立的本地库调用本地方法库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想实现这个规定的解决方案<一个href=\"http://stackoverflow.com/questions/10649119/calling-native-method-twice-of-third-party-library-in-an-activity-causes-the-and\">stackoverflow帖子。

I am trying to implement the solution stated in this stackoverflow post.

作为解决方案建议,我创建了一个独立的本地库。这怎么我已经实现了这样的库为止。

As the solution suggests, I created a independent native library. This how I have implemented that library thus far.

#include "zoom_Main_VideoPlayer.h"
#include <dlfcn.h>

void *handle;
typedef int (*func)(int); // define function prototype
func myFunctionName; // some name for the function

JNIEXPORT void JNICALL Java_zoom_render_RenderView_naClose(JNIEnv *pEnv, jobject pObj) {

    handle = dlopen("path to nativelibrary1.so", RTLD_LAZY);
    myFunctionName = (func)dlsym(handle, "Close");
    myFunctionName(1); // passing parameters if needed in the call
    dlclose(handle);
    return;
}

据该解决方案,另建独立的本地库(工具库)来加载和卸载其他库。因此,我试图加载在这个独立的库卸载nativelibrary1。例如,在该其它本地库的本机方法是这样

According to the solution, build another independent native library (utility library) to load and unload the other libraries. Thus, I am trying to load and unload nativelibrary1 in this independent library. For example, the native method in this other native library is such

// native method in nativelibrary1
JNIEXPORT void JNICALL Java_zoom_render_RenderView_naClose(JNIEnv *pEnv, jobject pObj) {

    if (!is) {
        do_exit(is);
    }
    else {
        do_exit(NULL);
    }

    LOGI(0, "Clean-up done");
}

我不知道我应该如何修改nativelibrary1因为它们并不直接在java code叫了本地方法(的的nativelibrary1 LIB不直接在java $静态加载块C $ç的)。

另外我应该在修改的typedef INT(* FUNC)(INT); //定义函数原型来适应nativelibrary1方法的类型?

Also am I supposed to change typedef int (*func)(int); // define function prototype to fit the type of the method in nativelibrary1?

推荐答案

同类不清楚你想要什么功能的的,但如果我理解,你希望你的Java可调用的库是像下面的(假设C不是C ++)

Its kind of unclear what you want the function to do, but If I understand, you want your Java-callable library to be like the following (assuming "C" not C++)

#include "zoom_Main_VideoPlayer.h"
#include <dlfcn.h>
void *handle;
typedef void (*func)(); // define function prototype
func myFunctionName; // some name for the function
JNIEXPORT void JNICALL Java_zoom_render_RenderView_naClose(JNIEnv *pEnv, jobject pObj) {

    handle = dlopen("path to nativelibrary1.so", RTLD_LAZY);
    myFunctionName = (func)dlsym(handle, "Close");
    myFunctionName(); // passing parameters if needed in the call
    dlclose(handle);
    return;
}

和您的其他图书馆将是:

And your other library will be:

// native method in nativelibrary1
void Close() {
    if (!is) {
        do_exit(is);
    }
    else {
        do_exit(NULL);
    }
    LOGI(0, "Clean-up done");
}

由于您关闭()没有任何参数。您也可以让你的Java方法静态,这样的虚假pObj没有添加到本地方法的签名。

Because your Close() does not have any arguments. You may also make your Java method static so that the spurious pObj isn't added to the native method signature.

如果您所描述的方法应该做的事情,我可以做一个更好的建议。

If you described what the methods should do, I could make a better suggestion.

这篇关于在独立的本地库调用本地方法库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆