logo       

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

programming.swig

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

        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();

        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,

Ricardo

--
Ricardo Scachetti Pereira
Computer Engineer
Biodiversity Research Center
Natural History Museum
University of Kansas
1345 Jayhawk Boulevard
Lawrence, KS 66045-7561 USA
Tel: (785) 864-4655, Fax: (785) 864-5335
email: rpereira@xxxxxx


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

News | FAQ | advertise