简体   繁体   English

当使用JNI移植现有的C ++代码时,使用C或C ++与JAVA接口?

[英]When using JNI to port in existing C++ code, use C or C++ to interface with JAVA?

The existing codes that I'm trying to port in is implemented in C++. 我要移植的现有代码是用C ++实现的。 After I write my java wrapper and run javah on the class to get a .h header file, .... is there a "correct" way to do things? 在我写完Java包装程序并在类上运行javah以获取.h头文件之后,....有没有“正确”的处理方法? Should my corresponding wrapper for my existing code be written in C or C++? 现有代码的对应包装器应该用C还是C ++编写?

Thanks! 谢谢!

If you use plain JNI, you can write in both C and C++. 如果使用纯JNI,则可以使用C和C ++编写。 The important thing is that if you are using C++, the JNI functions (like void Java_com_yourpackage_YourClass_yourMethod(JNIEnv* env, ...) ) must be declared as extern "C" , but AFAIK javah is doing it automatically. 重要的是,如果您使用的是C ++,则必须将JNI函数(例如void Java_com_yourpackage_YourClass_yourMethod(JNIEnv* env, ...) )声明为extern "C" ,但是AFAIK javah会自动执行此操作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM