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
Apache CXF not mapping nested complex types correctly
Java UDP packets not received when using a public IP with the same source port
Store data in BaseActivity
Set JAVA_HOME PATH for java 1.8 OSX sierra not work
Adding Price to toppings
JAVA rest webservice returning 404 error, deployed on Tomcat in Linux CentOS
searching a file in a root drive in Java
weka Exception ArrayIndexOutOfBoundsException: 15 at weka.core.DenseInstance.value double pred = tree.classifyInstance(unlabeled.instance(i))
File checkin and checkout in Java
Mockito & PowerMock - class size limitations
Define unique key in hibernate
sort ArrayList based on criteria using SQL query or Java
Trying to retrieve value from Firebase, but getting null?
Issue with a simple app
Virtual keyboard for InputDialog on touch screen
Java 8 Streams: Collapse/abstract streams parts