Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/310.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/linux/28.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
为c++;python中要使用的库 我在Python中创建了一个仿真工具,需要一个C++库。如何将库与python接口?这个库很大,但我只想调用一些函数和类成员函数 到目前为止,我已经厌倦了使用CyType和Sug在C++代码的小位上,只是为了熟悉这个过程。p> C++类型的库必须已经编译成共享库,这不是问题。我使用cType调用共享库中的C++函数,但是你能用cType调用类成员函数吗? 如果我使用SWIG,我必须把C++库的所有头文件都包含在接口文件中,还是只包含那些我需要的函数?< < /P> 代码类型> /Cuth>可以调用C接口,或者C++接口,这些代码是外“C”< /代码>,但它不理解特定于C++的类,如std::string或成员函数_Python_C++_Ctypes_Swig - Fatal编程技术网

为c++;python中要使用的库 我在Python中创建了一个仿真工具,需要一个C++库。如何将库与python接口?这个库很大,但我只想调用一些函数和类成员函数 到目前为止,我已经厌倦了使用CyType和Sug在C++代码的小位上,只是为了熟悉这个过程。p> C++类型的库必须已经编译成共享库,这不是问题。我使用cType调用共享库中的C++函数,但是你能用cType调用类成员函数吗? 如果我使用SWIG,我必须把C++库的所有头文件都包含在接口文件中,还是只包含那些我需要的函数?< < /P> 代码类型> /Cuth>可以调用C接口,或者C++接口,这些代码是外“C”< /代码>,但它不理解特定于C++的类,如std::string或成员函数

为c++;python中要使用的库 我在Python中创建了一个仿真工具,需要一个C++库。如何将库与python接口?这个库很大,但我只想调用一些函数和类成员函数 到目前为止,我已经厌倦了使用CyType和Sug在C++代码的小位上,只是为了熟悉这个过程。p> C++类型的库必须已经编译成共享库,这不是问题。我使用cType调用共享库中的C++函数,但是你能用cType调用类成员函数吗? 如果我使用SWIG,我必须把C++库的所有头文件都包含在接口文件中,还是只包含那些我需要的函数?< < /P> 代码类型> /Cuth>可以调用C接口,或者C++接口,这些代码是外“C”< /代码>,但它不理解特定于C++的类,如std::string或成员函数,python,c++,ctypes,swig,Python,C++,Ctypes,Swig,对于SWIG,您可能只在SWIG接口文件中包含要向Python公开的头文件。例如: %module example %{ // This section is copied into the wrapper so the generated code can compile. // No wrappers are generated from this. #include "myheader1.h" #include "myheader2.h" %} %include "myheader

对于SWIG,您可能只在SWIG接口文件中包含要向Python公开的头文件。例如:

%module example

%{  
// This section is copied into the wrapper so the generated code can compile.
// No wrappers are generated from this.
#include "myheader1.h"
#include "myheader2.h"
%}

%include "myheader1.h"  // Wrap all functions directly declared in this header.    
int myfunc(int a, int b);  // Wrap only this one function in myheader2.h.

根据你想要的东西的抛光程度,Cython也让包装东西变得非常容易。还有一个Jupyter笔记本模块,它可以真正实现交互式测试/开发convenient@SamMasonCython可以用来从现有的库中包装C++代码吗?YUP,这里有很多关于“Cython C++”的Google的问答。看起来也很有用。细节在很大程度上取决于您试图在不同语言之间公开/共享的内容,最简单的方法是调用几个函数并传递本机数据类型,您可以使事情任意复杂化。例如,如果我只想使用库中的单个函数,但该函数依赖于库中的其他函数和类,那么我应该包含%{%}之间的所有头然后只包装下面所需的单个功能?@tristan yes,至少。