简体   繁体   中英

SWIG c++ to C# error unable to find entry point SWIGRegisterExceptionCallbacks_xxxx

So I got this simple C++ code that I try to wrap using swig 3.0.2 to generate the C# equivalent.

So here is the c++ code

myclass.hpp

#ifndef __MYCLASS__
#define __MYCLASS__

class myclass {
public:
    int add(int b, int c);
};

#endif

myclass.cpp

#include "myclass.hpp"

int myclass::add(int a, int b) {
    return a+b;
}

myclass.i

%module mymodule

%{
#include "myclass.hpp"
%}

%include "myclass.hpp"

So here is the swig command

swig -csharp -c++ -outdir csharp myclass.i

And here is the compilation command using MinGW

g++ -shared -I./ myclass_wrap.cxx myclass.cpp -o mymodule.dll

So then I try to use the generate code by swig in a console application and I get the following error:

Unable to find an entry point named 'SWIGRegisterExceptionCallbacks_mymodule' in DLL 'mymodule'.

So it is loading the mymodule.dll correctly but can't find the SWIGRegisterExceptionCallbacks_mymodule which seems weird ... it is present in the myclass_wrap.cxx with what seems to be the correct export keyword __declspec(dllexport)

Thanks for the help,

Cheers

So I've found the issue so others who runs into the same issue can have a solution.

Adding -add-stdcall-alias to the compiler fixed the issue:

g++ -shared -I./ myclass_wrap.cxx myclass.cpp -o mymodule.dll -add-stdcall-alias

Using a DLL explorer viewer software I noticed the functions ended with MyFunctionName@XX , which I believe cause the entrynotfoundexception since it is looking for MyFunctionName and not MyFunctionName@XX .

So swig generated the c code with __stdcall and MinGW generated those MyFunctionName@XX when in __stdcall

More information can be found here : http://wyw.dcweb.cn/stdcall.htm

Cheers,

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM