Linux上MathGL的安装和使用
本人参考http://mathgl.sourceforge.net/doc_en/index.html#SEC_Contents
MathGL官网教程第一种方案在Ubuntu上对MathGL进行了编译安装,但是发现安装后的mgl2文件中.h文件缺少很多,了解到是如下原因导致
There are several additional options which are switched off by default. They are: enable-fltk, enable-glut, enable-qt4, enable-qt5 for ebabling FLTK, GLUT and/or Qt windows; enable-jpeg, enable-gif, enable-hdf5 and so on for enabling corresponding file formats; enable-all for enabling all additional features. For using double as base internal data type use option enable-double. For enabling language interfaces use enable-python, enable-octave or enable-all-swig for all languages. You can use WYSIWYG tool (cmake-gui) to view all of them, or type cmake -D enable-all=on -D enable-all-widgets=on -D enable-all-swig=on . in command line for enabling all features.
按照该方案配置cmake 文件后,并没有达到效果。转而使用其他方式,过程如下:
- sudo apt install build-essential
- sudo apt install libmgl-dev
通过dev的方式安装后对应的.h文件都会默认存放在/usr/include/mgl2文件下。
测试代码:
#include <mgl2/mgl.h>
#include <mgl2/glut.h>
#include <mgl2/qt.h>
int sample(mglGraph *gr){
gr->SetRange('x', 0, 1);
gr->Box();
gr->FPlot("sin(2*pi*x)");
return 0;
}
int do_draw(mglGraph *graph)
{
graph->Rotate(60,40);
graph->Box();
return 0;
}
int main(int argc, char* argv[])
{
mglQT gr(sample, "MathGL demo");
gr.Run();
return 0;
}
编译命令:
g++ test.cpp -o test -lmgl -lmgl-wnd
运行结果:
工程使用时,直接在CMakeLists中添加
#添加链接库
target_link_libraries(mathgltest m -lmgl -lmgl-wnd)
参考:https://solarianprogrammer.com/2020/06/25/getting-started-mathgl-windows-linux/#mathgl_installation_linux
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)