SWIG Python wrapper.

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

SWIG Python wrapper.

galaxyblazer
This post has NOT been accepted by the mailing list yet.
Hi all. I have some problem to make wrapper in specific way .

I have a C++ library (libmylib.so for example) which compiles into /usr/local/lib folder and I have a mylib.h header file in /usr/local/include.
Here is a mylib.h:

#pragma once
#include <string&gt>

myEnum {foo=0, bar};
myEnum getResult(const std::string& path, std::string& result);



And I have an interface file for all this with some overload of getResult method. (IN python all strings immutable and I can't get result from input parameter . )

%module mylib
%include <std_string.i>

%{
    #include "mylib.h"
%}

%inline %{
    std::string getResult(const std::string& path) {
        std::string temp;
        getResult(path, temp);
        return temp;
    }
%}

In this combination I have wrapper that works .
BUT!!!
I don't want have any implementation of function in the interface file. For this reason I'm trying to put overloaded method into additional file (For example mylib_m.h/.cpp).

mylib_m.h:

#include <string>

std::string getResult(const std::string& path);

mylib_m.cpp:

#include "mylib_m.h"
#include "mylib.h"

std::string getResult(const std::string& path) {
        std::string temp;
        getResult(path, temp);
        return temp;
    }



And than I modified my interface file to this :

modified .i file

%module mylib
%include <std_string.i>
%include "mylib_m.h"
%{
   
%}



When I built my wrapper with that modifications, I found that it doesn't works when I try to import it to the python code. I have an error: there are undefined symbols in _mylib.so .

So question . How to do that what I want?