Showing posts from June, 2019

Calling C++ native code from Java

Recently, I faced a lot of troubles in finding a good article that completely explains the process of calling a C++ native function from Java. I did some experiments and I finally succeeded. I will be sharing the instructions step-by-step.

In this article, I will be taking a very basic example of taking an array of numbers as input in Java, computing their sum using a native C++ code and then printing the output back to the console using Java. I would be keeping the article concise and would encourage you to explore the official documentation in case you run into some issues. Also, I will be using Windows and GCC compilers. A 32-bit C++ compiler is compatible with 32-bit Java compiler and a 64-bit C++ compiler is compatible with 64-bit Java compiler. MinGW doesn't publish x64 versions of GCC compilers for Windows (it is only available for Linux). So, in case you are using Windows make sure that you install 32-bit Java version. I am also assuming that you are using JDK 8 or some a…