简体   繁体   English

为C ++代码编写python包装器

[英]Writing a python wrapper for c++ code

I modified a C++ code (Kraskov_v1.C) and I now wish to call it from Python. 我修改了C ++代码(Kraskov_v1.C),现在希望从Python调用它。

I am able to convert the C++ code (Kraskov_v1.C) into a .so file and integrate it into my python library. 我能够将C ++代码(Kraskov_v1.C)转换为.so文件,并将其集成到我的python库中。 However when I try and import the library, it throws up an error. 但是,当我尝试导入库时,它将引发错误。 The error says "undefined symbol: _Z8mir_xnynPPdiiiiS_S_S_" 错误显示为“未定义符号:_Z8mir_xnynPPdiiiiS_S_S_”

mir_xn_yn is a function (written in another c++ file namely miutils) that my Kraskov_v1 code calls. mir_xn_yn是我的Kraskov_v1代码调用的一个函数(写在另一个c ++文件即miutils中)。 I included the header file 我包含了头文件

include "miutils.h" 包括“ miutils.h”

in my file containing Kraskov_v1. 在我的包含Kraskov_v1的文件中。

Here is the setup.py file I wrote to build and install this package. 这是我为构建和安装此软件包而编写的setup.py文件。

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

from distutils.core import setup
from distutils.extension import Extension
from Cython.Distutils import build_ext
import numpy.distutils.misc_util

setup(name='Kraskov_v1',
      version='0.1.0',
      ext_modules=[Extension('_Kraskov_v1',sources =        
      ["Kraskov_v1.i","Kraskov_v1.C"],
      include_dirs = ['src'])
      ])

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

Can someone tell me whats wrong? 有人可以告诉我怎么了吗? I am new to python and c++ and would appreciate some help. 我是python和c ++的新手,希望能提供一些帮助。

The Extension needs a list of libraries to link with after compiling. Extension需要一个库列表,以便在编译后进行链接。

Missing symbols means a required library is not linked to the shared object ( .so ) and definitions from that library are not available. 缺少符号表示必需的库未链接到共享库( .so ),并且该库中的定义不可用。

setup(name='Kraskov_v1',
      version='0.1.0',
      ext_modules=[Extension('_Kraskov_v1',sources =        
          ["Kraskov_v1.i","Kraskov_v1.C"],
          include_dirs = ['src']),
          libraries=['kraskov', <..>],
      ])

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM