Click here to Skip to main content
15,888,014 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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:
C++
#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 . )

C++
%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:

C++
#include <string>

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


mylib_m.cpp:

C++
#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

C++
%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?

What I have tried:

I tried way that I described in problem.
Posted
Updated 5-Jan-17 10:27am

1 solution

Just from browsing at your code, if that compiled, that should work... what are the undefined symbols that it's complaining about? ...perhaps you forgot to link a dependency (i.e. libpython is a dependency that may initially be overlooked).
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900