Python, std_wstring.i and %import
Jim Easterbrook <[email protected]> Mon, 13 Sep 2021 12:00:25 +0100
| Newsgroups | gmane.comp.programming.swig |
|---|---|
| Message-ID | <[email protected]> |
I encountered an unexpected problem when using std_wstring.i in some
SWIG Python modules. Module B uses %import to get definitions from
module A, and both modules contain %include "std_wstring.i". During
compilation of Module B (on Windows) I got "error C3861:
'SWIGPY_UNICODE_ARG': identifier not found". Module A compiles without a
problem.
SWIGPY_UNICODE_ARG is defined in pywstrings.swg inside %{ %} brackets.
It appears that when module A is imported into module B the contents of
pywstrings.swg are imported with it, but without the SWIGPY_UNICODE_ARG
definition. (I assume that's what's happening, but I don't fully
understand SWIG's various import & include directives.)
My solution has been to wrap the use of std_wstring.i in SWIGIMPORTED
guards:
#ifndef SWIGIMPORTED
%include "std_wstring.i"
#endif
I'm now wondering why I haven't run into similar problems with other
SWIG library modules.
--
Jim Easterbrook <http://www.jim-easterbrook.me.uk/>