如何在 C/C++ 程序中嵌入 GNU Octave?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9246444/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-27 12:32:22  来源:igfitidea点击:

How to embed the GNU Octave in C/C++ program?

c++ccontrolspackageoctave

提问by reyoung

I want to calculate some matrix algorithms using the GNU Octave library. I know I can use C/C++ API of Octave for basic use. However the method I want to use is not in the default packages of Octave. So how to use Octave's control packagein the C/C++ program?

我想使用 GNU Octave 库计算一些矩阵算法。我知道我可以使用 Octave 的 C/C++ API 进行基本使用。但是我想使用的方法不在 Octave 的默认包中。那么如何在C/C++程序中使用Octave的控制包呢?

回答by Appleman1234

Something like this

像这样的东西

embed.cpp

嵌入.cpp

#include <iostream>
#include <octave/octave.h>

int main(int argc,char* argv)
{
??int?embedded;
??octave_main(argc,argv,embedded=0);??
??return?embedded;
}

Then

然后

mkoctfile embed.cpp --link-stand-alone -o embedin order to make a standalone executable.

mkoctfile embed.cpp --link-stand-alone -o embed为了制作一个独立的可执行文件。

To call octave functions whether they are provided by scripts or octaveforge modules you can then use feval which takes the octave function name as string, an octave_value_list of the input variables to that function, and the number of variables to that function as integer.

要调用八度函数,无论它们是由脚本还是octaveforge 模块提供的,您都可以使用 feval 它将八度函数名称作为字符串,该函数的输入变量的八度值列表,以及该函数的变量数作为整数。

See herefor further information.

请参阅此处了解更多信息。