I can explain more on the question. I would like to write a program in Java which calls a native method that's described in a C++ program.
public class Sample
// A native method that receives nothing and returns void
private native void test();
public static void main(String args)
new Sample().test(); // invoke the native method
using namespace std;
void test() // native function
// function definition
I compiled and builded the Sample.cpp in a Visual C++ environment into a .dll. Now I tried to execute the java program with this dll and it said it could not find dependent libraries. I tried the following too.
I added additional dependencies to the program to include the jni header from JAVA_HOME/include and JAVA_HOME/include/Win32. I builded a dll and tried to execute the java code and hit again at the same error "Unsatisfied Link Error : Cant find dependent libraries".
So perhaps Java isn't lying and it really cannot find the library. How are you running the java application? Where do you put the native DLL? Are you sure you are compiling the DLL for the correct CPU architecture that matches your Java runtime (32 bits/64 bits) ?
But i tried to write the code in a cpp file and tried to generate a dll offshore out of Visual C++ environment. I obviously had to have the libraries and hence linked them during execution to form the dll.
But I am unsure of the libraries. I am linking them during execution but I get errors like
xstring:2011:20:error: const class std::basic_string(cahr,std::char_traits<char>.................................) has no member named '_Myres' . This is the last line of a two-to-three page running errors. I think there is some problem with the headers and libraries I use for execution.
I think there is some ambiguity in my previous statements. To be more clear, I am trying to generate a dll first and then going to link it to execute the java program. Now the error I recently posted is for the formation of dll file. I cant generate a dll first of all. After that only, I can jump into execution of the java program.
Sorry about that. I guess I was typing a lot. To make things clear,
I compiled the cpp code into a dll in Visual C++ environment and tried to link it during execution of the java code which gave me "Cant find dependent libraries".
Then I tried to write the code offline in Notepad and tried to link dependent libraries to compile the code into a dll which raised a two-to-three page running error. Sample error is "xstring:2011:20:error: const class std::basic_string(cahr,std::char_traits<char>.................................) has no member named '_Myres' ".
So basically I tried it in two different ways and got two different errors.
I got "Cant find dependent libraries" error when I dynamically linked the Visual C++ generated dll to execute the java program.
I got a two page error (sample - xstring:2011:20:error: const class std::basic_string(cahr,std::char_traits<char>.................................) has no member named '_Myres' ) when I try to link or include the libraries and dependencies required to compile the cpp code into a dll.
*g++ --options -I"Path to headers and libraries required for compiling the cpp code" File.cpp*