从Java调用C ++函数 [英] Calling C++ functions from Java

查看:133
本文介绍了从Java调用C ++函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个Java应用程序,其中我需要调用一些C ++函数(从Google Talk库libjingle)。目标是在Google App Engine(仅支持Python或Java)上运行它。



我如何做?


<你需要在你的java代码中定义 native 方法来实现你想在C ++中实现的任何东西,并且直接访问您的本地代码。然后在你的代码上运行 javah ,它将为你生成C头文件,你需要提供C ++实现。



与任何其他方法一样,您可以从Java代码调用的本地方法,仍然可以使用C ++编写的实现,并直接与任何其他本地库交谈。



然后,您需要设置java.library.path系统属性以包含您需要的共享C / C ++库:在这种情况下,将需要google库和您自己的JNI实现库。


I am developing a Java application in which I need to call some C++ functions (from Google Talk library libjingle) . The objective is to run it all on Google App Engine (which only supports Python or Java).

How can I do this?

解决方案

You need to define native methods in your java code for whatever you want to be implemented in C++ and directly access your native code. Then you run javah on your code and it will generate the C header files for you and you'll need to provide C++ implementations.

The native methods you can call from your Java code like any other methods and still they'll have their implementation written in C++ and talking to whatever other native library directly.

You then need to set the java.library.path system property to include the shared C/C++ libraries that you require: the google library and your own JNI implementation library would be required in this case.

这篇关于从Java调用C ++函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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