Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/142.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
Python与C++的接口 我想在Python和C++之间进行接口。我试着在最简单的情况下开始做这件事,例如寻找平均值。我的主要语言是python_Python_C++_Swig - Fatal编程技术网

Python与C++的接口 我想在Python和C++之间进行接口。我试着在最简单的情况下开始做这件事,例如寻找平均值。我的主要语言是python

Python与C++的接口 我想在Python和C++之间进行接口。我试着在最简单的情况下开始做这件事,例如寻找平均值。我的主要语言是python,python,c++,swig,Python,C++,Swig,1函数getInput python 2函数计算器++ 3函数显示Python 我的python文件main.py如下所示: function getInput(x,y) //Here I want to add the function CalculateMean written in cpp file function displayMean(m) CalcMean.h int CalculateMean(int x,int y) CalcMean.cpp mean = Calcul

1函数getInput python

2函数计算器++

3函数显示Python

我的python文件main.py如下所示:

function getInput(x,y)
//Here I want to add the function CalculateMean written in cpp file
function displayMean(m)  
CalcMean.h

int CalculateMean(int x,int y)
CalcMean.cpp

mean = CalculateMean(x,y)    
{
mean = (x+y)/2;
return mean;
}

我尝试过使用SWIG,但我是一个新手,无法解决它。我们将非常感谢您提供的任何基本帮助。

您需要一个简单的swig接口文件,用于导入CalcMean.h并生成一个模块,类似于以下内容的模块导入mymodule.i文件:

%module mymodule
%{
    #include "CalcMean.h"
%}

%include "CalcMean.h"
然后你可以用类似的东西启动swig

./swig-python-omymodule.omymodule.i

这将生成一个要编译为.so/.dll文件的.o文件,以及导入模块所需的.py文件