Using a compiled DLL in Java with SWIG and Visual Studio 2015
I have a compiled DLL (C/C++) and I have to use it in Java. So I want to use SWIG to create a wrapper . I followed all the tutorials like: How to create a DLL with SWIG from Visual Studio 2010 http://www.swig.org/Doc3.0/Java.html SWIG JNI Interface with DLL and declarations only But in all the examples no precompiled DLL and/or Java and/or Visual Studio (2015) were used. When using an own cpp file for the implementation (and don't use an external DLL, implementing the header) everything works fine (compile to a single DLL and calling from Java). So what do I want: Having a precompiled DLL (example.dll), the header for that (example.h) and the SWIG header file (example.i). Compile everything to a "wrapper DLL", load this one in Java and accessing the precompiled DLL (example.dll). My steps in detail: New VS class library project Add the h and i file Add the custom build step for the i file (like in the example) Java files and the example_wrap.cxx file is generated Add the example_wrap.cxx, add Java includes and don't use precompiled headers Compile example_wrap.cxx to example.lib (Is that right?) Setting project settings like in the tutorials (no clr, add java-includes, no precompiled headers) Now creating the whole project fails with linking error LNK2019 in example_wrap.obj. Can someone help me? What I also don't get: The result will be "example.dll". I have to use this DLL in Java (with System.load/loadLibrary). How can this SWIG DLL access the "original" example.dll with all the logic inside? Using Python instead of Java results in the same failure (LNK2019 - unresolved external symbol).
Basically you need to "forward" the calls to the external library. I.e. import symbols from there into the wrapper library and link with the external DLL lib file. If you do not have such a lib file for the DLL, you need to either create it (e.g. using some tool the create lib from the DLL), or load the external library/import symbols at runtime (LoadLibrary/GetProcAddress).
The answer from axalis was absolutly right. Here some details: Add example.cpp Load the precompiled DLL (example.dll) with LoadLibrary and save a reference Load methods from there with GetProcAddress and save a reference for each method Write an "implemantation" for each method where you just call the method loaded before Compile and link everything to exampleWrap.dll and load this dll in the Java project
Run-time error. Integer convert to string
How to pass a parameter to a callback method
Why is not detecting my parametrized class type?
How can I get a List of objects using Unirest for Java?
Error inflating class AppCompatButton
How to extract a string from a bean returning string array in XML
Scanner continuous loop
Findbugs is telling me that I have comparison of nonnegative value with -1 for no apparent reason
passing value from signup to register if validation is true
Cant extract single files from Tar, 0kb size, Java
check for numeric input java
cannot find symbol, keyEvent constants java
Comparing two numbers using if/else statements
Certificate Authentication and Authorization with Apache from a Java Application
Error with float multiplication and display in GUI
Calling method from another class confusion (Robot class)