문제

I've written a C++ DLL using Visual Studio 2010. So, I have a DLL file with some classes and methods exposed. This DLL is being used in another C++ project without problems.

Now, I want to create a Java/Python wrapper, to use my library in other Java/Python projects. After reading about the options, I decided to go with SWIG. So, I've written some interface files to tell SWIG which of my classes and methods I want to wrap (Basically, those exposed with __declspec(dllexport) in my header files). And I've configured Visual Studio 2010 to raise SWIG just after the DLL file is generated. Basically, this SWIG line is executed after the successful generation of DLL file:

swig.exe -c++ -java "%(FullPath)"

Being "FullPath" the path to a .i file.

My .i files look like this:

%module my_module

%{
#include "OneOfMyHeaders.h"
%}

%include <windows.i>

%include "OneOfMyHeaders.h"

OneOfMyHeaders.h contains myFunction, that I want to call from Java. I can successfully run SWIG, and .java/.class files are generated. But when I try to run a dummy Java main program (just call Java wrapper over C++ method myFunction), I get this error

Exception in thread "main" java.lang.UnsatisfiedLinkError: my_moduleJNI.myFunction()V
...

This happens with any call. And it also happens if I modify my interface file this way:

%module my_module

%{
#include "OneOfMyHeaders.h"
%}

%include <windows.i>

__declspec(dllimport) void myFunction();

So, instead of directly including the header files (it may contain other header files, and this may drive to problems, as I've read in doc), I expose my functions. Same error.

What am I doing wrong?

Should I specify any other SWIG parameter?

Is there any other better option than SWIG?

I want Java and Python wrappers, but getting Ruby/PHP ones won't hurt. I chose SWIG for that reason, mainly.

Many thanks in advance

도움이 되었습니까?

해결책

Solved. I wasn't including the generated .cxx file in the Visual Studio project. So, its functions weren't linked. After including it, everything works fine.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top