title: Calling C++ library in java using JNA
body: <p>I have created a c++ lib for function given below          </p>
  
  <pre><code>#include "Test.h" 
  #include "iostream"      
  extern "C" int add(int x,int y) {    
  Add instance;
  return instance.add(x,y);  
  }
  Add::Add()
  {
  std::cout&lt;&lt;"In Add Constructor::"&lt;&lt;std::endl;
  }   
  int Add::add(int x,int y) {
  return x+y;  
  }
  </code></pre>
  
  <p>then i used this library in another c++ and call its function.</p>
  
  <pre><code>#include "Test1.h"
  #include "iostream"
  Test1::Test1()
  {
  std::cout&lt;&lt;"InConstructor of Test1 Library::"&lt;&lt;std::endl;
  int result = 0;
  result = CallingLibFunction(10,20);
  std::cout&lt;&lt;"SUM RESULT : "&lt;&lt;result&lt;&lt;std::endl;
  }
  extern "C" int CallingLibFunction(int x,int y) {
  
  Test1 instance;
  return instance.CallingLibFunction(x,y); 
  } 
  int Test1::CallingLibFunction(int x, int y)
  {
  int value = addFunc.add(x,y);
  return value;
  }
  </code></pre>
  
  <p>now i have created new library for Test1. and then use it in my jna example in java.</p>
  
  <pre><code>import com.sun.jna.Library;
  import com.sun.jna.Native;
  public class Test {
      static{
          System.setProperty("java.library.path", "/root/Desktop/Pragati/OSGI/JNA/JNAExample/JNASimpleExample/JNAApp/bin");
          System.out.println("java lib path : " + System.getProperty("java.library.path"));
          //System.loadLibrary("src");            
      }
  
      public interface Test1 extends Library
      {
          Test1 INSTANCE = (Test1) Native.loadLibrary("Test1", Test1.class);
          int CallingLibFunction(int x, int y);
      }
      //CallingLibFunction
      public static void main(String[] args) {
  
          Test1 lib = Test1.INSTANCE;
          System.out.println(lib.CallingLibFunction(10, 20));
      }
  }
  </code></pre>
  
  <p>now this program encounter error that is given below:</p>
  
  <pre><code>/usr/java/jdk1.8.0_25/bin/java: symbol lookup error: /root/Desktop/Pragati/OSGI/JNA/JNAExample/JNASimpleExample/JNAApp/bin/libTest1.so: undefined symbol: _ZN3AddC1Ev
  </code></pre>