python - Is f1(const char* str) different from f1(char* str) when applying SWIG to C++? -
i applying swig convert c++ library python library.
i have header file , source file (trivial things omitted):
test.h
void f1(char* str);
test.cc
void f1(const char* str) { /* */ }
when build it, not throw errors or warnings such mismatch.
but when import module generated swig in python:
>>> import (mymodule) importerror: /usr/local/lib/libmymodule.so: undefined symbol: _zn2f14str12iii
an error above occurs.
but, after fixing header , source have same arguments, const char* str
, error has been solved.
what wonder is, then, why c++ compiler , builder not throw error or warning, put thing becomes problem in swig , python.
indeed, char*
, const char*
different types.
you've declared 2 overloaded functions, , defined one. that's not error, long don't try call or otherwise use undefined one. if do, you'll link-time error; since you've built dynamic library, detected when library loaded - in case, python interpreter.
Comments
Post a Comment