现有的C ++(.H和.cpp)文件转换成Java为Android [英] Convert existing C++ (.h and .cpp) files to java for Android

查看:1176
本文介绍了现有的C ++(.H和.cpp)文件转换成Java为Android的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的Eclipse下开发的机器人。我有一些C ++(.H和.cpp),我希望在我的Andr​​oid应用程序使用的文件。我已阅读写频的C / C ++与Java本地接口并现在我知道如何使.so文件并将其导入到Android。但是,主要的问题是,

I am developing for Android under Eclipse. I have some c++ (.h and .cpp) files that I wish to use in my Android application. I have read Programmming in C/C++ with the Java Native Interface and now I know how to make .so file and import it to Android. But the main problem is that:

是否有转换C ++(.H和.cpp)文件到Java样式文件,我可以编译和创建.so库的任何工具?我听说过JNI - ?javah的和javac是该工具可以帮助我,如果他们能那么如何

编辑:

javah的是创建给定类C风格的头文件的有用工具。由此产生的头文件描述了C组术语类文件。虽然可以手动创建的头文件,这是几乎总是一个坏主意。 javah的确切地知道Java类型和对象映射到C型。例如,在Java的一个int映射到一个长期的C和Java中的长映射到一个64位的值,_int64,在本土code。如何使用本javah的?

任何人有如何使用那些在Android应用程序.so库实现的功能expiarance?如果任何人有code例子或有用的文章链接,请给。

在此先感谢!

推荐答案

您不转换C ++文件,以Java的方式。您需要创建一个JNI包装在你现有的C ++ code。这JNI包装实际上是C ++ code可通过Java调用。

You don't "convert C++ file to java style". You need to create a JNI wrapper around your existing C++ code. This JNI wrapper is actually C++ code that can be called by Java.

通过包装我的意思是,你不应该修改现有的C ++ code基地。此包装,或更好说,这的结合的一般应非常薄。该包装code只是为了揭露现有的功能,没有实现它们。这是更好地离开了执行中的(便携式)C ++ code基地。

By wrapper I mean that you shouldn't have to modify your existing C++ code base. This wrapper, or better said this binding should generally be very thin. The wrapper code is only meant to expose existing functionalities, not to implement them. It is better to leave the implementation in the (portable) C++ code base.

如果在code基不是太大,那么我建议你写此包装的手,在的的JavaTM的母语 接口 程序员指南和规范

If the code base isn't too large, then I recommend that you write this wrapper by hand, as explained in The JavaTM Native Interface Programmer's Guide and Specification

现在,如果你想绑定一个大型图书馆,它可能是有问题的。因此,对于工具,我没有使用过这一点,但看看痛饮和相关痛饮Java文档

Now, if you are trying to bind a large library, it may be problematic. So, in regard to tools, I haven't used that, but have a look at SWIG, and the relevant SWIG Java documentation.

根据网页的描述,它是什么,你要问的:

According to the homepage description, it's what you're asking for:

呷通常用于解析C / C ++   接口并生成胶水   code'的要求[使用Java,Python,PHP,   ...]调成C / C ++ code。

SWIG is typically used to parse C/C++ interfaces and generate the 'glue code' required for [Java, Python, PHP, ...] to call into the C/C++ code.

javah的可能是在某些情况下是有用的,但它不是你的要求。它提取JNI锅炉板code OUT在Java类中本地声明。关于javac的,它的Java编译器,这是无关紧要的。

javah can be useful in certain cases, but it's not what you ask for. It extracts JNI boiler plate code out of native declarations found in Java classes. Regarding javac, it's the Java compiler, that's irrelevant.

这篇关于现有的C ++(.H和.cpp)文件转换成Java为Android的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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