SWIG std::string& passing

L

Leonard J. Reder

Hello,

I have been trying to get this simple call to work with a SWIG
interface. The problem is I do not know how to pass a const char * or a
std::string & in python to SWIG wrapped code. I tried several of the
*.i libraries at http://www.swig.org/Doc1.3/Library.html. Most notably
the "std_string.i" And get the following:
Traceback (most recent call last):
File "<stdin>", line 1, in ?
File
"/home/soa/dev/users/reder/Dshell++Pkg-reder01/lib/PYTHON/Dspace/Dnoise_Py.py",
line 1340, in SetDestFilename
def SetDestFilename(*args): return
_Dnoise_Py.WriterBMP_SetDestFilename(*args)
TypeError: argument number 2: a 'std::string *' is expected,
'str(test.bmp)' is received

The C++ method is:

void WriterBMP::SetDestFilename (const std::string& filename)

This should be easy to pass the filename to? Do you have an example?
What do I add to the *.i file?

Thanks for any and all replies,

Len

--
===================================
Leonard J. Reder
Home office email : (e-mail address removed)
Lab email : (e-mail address removed)
Lab web page : http://reder.jpl.nasa.gov
===================================


--
===================================
Leonard J. Reder
Home office email : (e-mail address removed)
Lab email : (e-mail address removed)
Lab web page : http://reder.jpl.nasa.gov
===================================
 
J

jchiang

Add the line

%include stl.i

to your .i file. This will make other stl containers available, in
addition to string. Make sure you put this line before any include
directives for classes that use std::string. SWIG requires classes to
be declared before they are used in order for the interfaces to be
exposed completely.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,070
Latest member
BiogenixGummies

Latest Threads

Top