views:

41

answers:

2

Hello, I currently have some C++ code that I want to compile into a shared library that I can dynamically link to a Java application during runtime using the Java Native Interface (JNI). The problem that I'm facing is - the C++ code that I'm trying to compile calls on another library itself, making use of a lot of classes and different header files. When I try to make it into a .dll file, I get a lot of linker errors (saying that I have unresolved external symbols - all of which belong to the source code that my C++ code calls from). Now I don't want to have to copy all of the external code (which is actually a library called VTK) into my own source - I just want a dynamically linkable library that has my own C++ code's functionality (which means it'd would need to be able to still recognize the external code that I don't want to duplicate).

Please feel free to ask any leading questions.

+2  A: 

You'll have to link against the other library, either statically (if it's a plain static lib) or dynamically if it's a DLL. There is no other way to ensure that both the linker and the loader can resolve the symbols.

Timo Geusch
+1  A: 

When you link a Windows DLL, you have to tell it where any symbols that it uses but does not define can be found. If you link against a static library, all the code for that library will be copied into your DLL. However, if you link against another DLL, the code for that library remains in the DLL, and all that is bound into your DLL are links to the other DLL. So, if VTK is provided as a DLL, you should be able to link against it and not bloat your own DLL. The one tricky part is that, for a given DLL, you don't actually link against the .dll file itself, you link against what is called a "import library", which usually has the same base name as the DLL and a .lib extension. So if VTK is available in the form of a VTK.dll file, you should look for a corresponding VTK.lib file, and add it to the link command that builds your DLL.

SCFrench
Any idea of how I could do that using cmake?
sparkFinder