SWIG Python包装器。 [英] SWIG Python wrapper.

查看:101
本文介绍了SWIG Python包装器。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好。我有一些问题,以特定的方式制作包装。



我有一个C ++库(例如libmylib.so),它编译成/ usr / local / lib文件夹,我在/ usr中有一个mylib.h头文件/ local / include。

这是一个mylib.h:

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);





我有一个接口文件,所有这些都有一些getResult方法的重载。 (在python中所有字符串都是不可变的,我无法从输入参数中获得结果。)





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;
    }
%}





在这个组合中我有包装工作。

但是!!!

我不希望在接口文件中有任何函数实现。出于这个原因,我试图将重载方法放入附加文件中(例如mylib_m.h / .cpp)。



mylib_m.h:





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:





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;
    }





而且我修改了我的界面文件:



修改.i文件





And than I modified my interface file to this :

modified .i file

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





当我使用这些修改构建我的包装器时,我发现当我尝试导入时它不起作用它到python代码。我有一个错误:_mylib.so中有未定义的符号。



所以问题。怎么做我想要的?



我尝试过:



我试过我在问题中描述的方式。



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.

推荐答案

只是浏览你的代码,如果编译,那应该工作......什么是未定义的符号它在抱怨吗? ...也许你忘了链接一个依赖项(即libpython是一个最初可能被忽略的依赖项)。
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).


这篇关于SWIG Python包装器。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆