logo       

Re: Can't use _declspec(dllimport) in SWIG to import data from DLL: msg#00121

programming.swig

Subject: Re: Can't use _declspec(dllimport) in SWIG to import data from DLL

Pereira, Ricardo Scachetti wrote:

Hi, there.

I'm building a Java interface for some C++ classes I have (SWIG 1.3.21 + Windows + Visual C++ 6.0). Those classes exist in a DLL. In that DLL there is one global object that is being exported from the DLL as:

class _declspec(dllexport) Log g_log();

It is imported by the clients of my DLL by the code:

class _declspec(dllimport) Log g_log();

Neither line is accepted by SWIG. So I went ahead and put macros defining both _declspecs and set them to blank in the SWIG interface file.

I could get away with the _declspec(dllexport) part, but without the _declspec(dllimport) I can't get the SWIG dll to link. It can't find the symbol "class Log g_log()".

In fact, by omitting the _declspec(dllimport), VC++ assumes that is an export declaration so I can't get to tell the compiler to look for that symbol in a dll.

As expected SWIG generates this:

class Log g_log();

SWIG generates what you tell it to. How did you get SWIG to do this?

My current workaround is to manually change the c++ file generated by SWIG to have this instead:

class _declspec(dllimport) Log g_log();

Then all works fine.
Does anyone has a better idea to solve the problem?
Regards,


You add stuff into the wrapper file using %{ %}...

%{
class _declspec(dllimport) Log g_log();
%}

SWIG won't parse any of this and will merely copy it all into the wrapper file.

William
_______________________________________________
Swig maillist - Swig@xxxxxxxxxxxxxxx
http://mailman.cs.uchicago.edu/mailman/listinfo/swig



<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

News | FAQ | advertise