Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Example of using C++ classes from Java. Showcases SWIG, JNA and JNI

Notifications You must be signed in to change notification settings

lwei3600103/java-cpp-example

Open more actions menu
 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
10 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Example of using C++ code from Java

This repository contains three examples of calling a simple C++ library from Java code.

The library doesn't do anything but contains a class, MyClass, forcing us to support C++ (and not just plain C).

CMake is used to build this, since locating the dependencies got outside the range of my make-fu. The project is supposed to be portable to all major platforms.

Three different wrappers are used, documented below.

SWIG

This needs the SWIG tool: http://www.swig.org/

SWIG parses the C++ header file and generated both the C++ JNI code and the Java native and helper classes.

JNA

JNA allows Java code to use C dynamic libraries directly. Because our library is in fact C++, a small wrapper is included that wraps it as C code.

You will need the JNA jar to run this: https://github.com/twall/jna

JNI

This examples uses JNI directly, without auto-generation. The MyClass class in Java code just declares its methods as being "native", they a reprovided by the dynamic library.

About

Example of using C++ classes from Java. Showcases SWIG, JNA and JNI

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • CMake 68.5%
  • C++ 17.0%
  • Java 14.5%
Morty Proxy This is a proxified and sanitized view of the page, visit original site.