MathGL windows cmake编译

0、demo运行成功

 MathGL使用参考①:
C++数据可视化MathGL使用简示_vaincury的博客-CSDN博客_c++ 数据可视化

 

一、MathGL cmake编译

 工具:MathGL

MathGL使用参考①:
C++数据可视化MathGL使用简示_vaincury的博客-CSDN博客_c++ 数据可视化

 文中作者编译好的:登录 - Gitee.com

 按照作者编译好的方式,并将配置导入工程,出现的错误为:

编译没通过的根本原因:2.2节的动态库、静态库没配置好。

1. link2019的问题描述为:

1.1 P.S. lib和dll的区别 

lib为静态库;dll为动态库,在运行的时候使用,一般放在exe所在目录下。
link一般时找不到源文件.cpp的位置,即lib的位置

2 MathGL通不过,只要自己重新编译MathGL

MathGL编译需要的材料

  1. MathGL源码:V8.0
  2. cmake——cmake gui挂了,改用cmake命令行。cmake gui容易出现路径问题
    windows & linux下cmake gui都容易出现莫名error,无法解决。碰运气。
    最好还是熟悉一下cmakeFileLists.txt中的内容,然后命令行给参数,来编译!遇到好多次坑了。
  3. zlib——————安装了annoconda的话,里面直接就有。自己重新编还挺头疼的
  4. libpng————annoconda直接就有。自己重新编还挺头疼的

1. MathGL源码下载,地址:Download (MathGL 8.0)

 2. cmake下载——『略去不表』

3. libpng下载 & zlib下载——我是annoconda自带,没有用下载的这些
地址:libpng Home Page

libpng 以 ANSI C (C89) 源代码的形式提供,需要zlib 1.0.4 或更高版本(出于性能和安全原因,建议使用1.2.5或更高版本)。

 zlib下载地址:zlib Home Site

 2.1 使用cmake进行编译

参考教程:C++可视化利器MathGL的Windows编译指南_vaincury的博客-CSDN博客_mathgl

 ①cmake的bug

bug现象:“error in configuration process project files may be invalid” 

 bug原因:未知

解决办法:!!!!! 换cmake 命令行用

之前遇到过类似问题:但用命令行cmake没有问题,cmake-gui就有问题

 ② 使用命令行cmake来编译

 ③ 解决办法:使用vs2019的Native Tools Command Prompt工具打开命令行

进入mathgl的文件夹 

 

1. 输入一下命令,表明libpng和zlib的位置,然后编译。 
一定要找准libpng的位置,而且这里给的是release的lib和include,所以VS2019的编译要通过Release编译。

 cmake命令行设置如下:给出几个路径,include路径、lib路径;还区分是Release的路径和Debug的路径。

cmake . -DPNG_LIBRARY_RELEASE="D:/miniconda3/Library/lib/libpng.lib" -DPNG_PNG_INCLUDE_DIR="D:/miniconda3/Library/include" ZLIB_INCLUDE_DIR="D:/miniconda3/Library/include" -DZLIB_LIBRARY_RELEASE="D:/miniconda3/Library/lib/z.lib" enable-mgl2=true

2. 编译结果: 

3. 生成了解决方案:然后使用vs2019打开.sln,进行编译 

 出现的

 出现的问题:unicode乱码 不用care这个问题

Visual Studio 2019修改编码UTF-8_有人_295的博客-CSDN博客_vs编码格式在哪改

 4. 编译成功:mgl-static为启动项

 

5. 看源码里面的demo教程

mathGL doc 教程位置:http://mathgl.sourceforge.net/doc_en/index.html

由于MathGL官网上面没有看到C++的太多教程只有一个,如下:

教程一:

#include <mgl2/mgl.h>
int main()
{
  mglGraph gr;
  gr.FPlot("sin(pi*x)");
  gr.WriteFrame("test.png");
}

教程二:来自  C++数据可视化MathGL使用简示_vaincury的博客-CSDN博客_c++ 数据可视化

#include "mgl2/mgl.h"
int main(int, char **)
{
    using namespace cv;
    //创建gr对象,指定图像大小为800x500,kind=0说明不使用OpenGL
    mglGraph gr(0,800,500);
    
    //数据准备
    std::vector<float> datavec1{ 1,2,3,4,5,6 ,7,};
    std::vector<float> datavec2{ 2,4,9,1,6,8, 8,};
    mglData x(datavec1);
    mglData y(datavec2);

    //通过给定数据计算合适的显示范围
    auto minx = *std::min_element(datavec1.begin(), datavec1.end());
    auto miny = *std::min_element(datavec2.begin(), datavec2.end());
    auto maxx = *std::max_element(datavec1.begin(), datavec1.end());
    auto maxy = *std::max_element(datavec2.begin(), datavec2.end());
    auto x_margin = (maxx - minx) / datavec1.size();
    auto y_margin = (maxy - miny) / datavec2.size();
    
    gr.SetRanges(minx - x_margin, maxx + x_margin, miny - y_margin, maxy + y_margin);
    //显示坐标轴
    gr.Axis();
    //显示图片框
    gr.Box();
    //Plot、Barh、Mark等等可选
    gr.Plot(x, y, "y+");

    //用OpenCV显示图片
    Mat pic(gr.GetHeight(), gr.GetWidth(), CV_8UC3);
    pic.data = const_cast<uchar*>(gr.GetRGB());
    imshow("test", pic);

    //保存图片
    std::cout << "write image as \"test.png\"." << std::endl;
    gr.WritePNG("test.png");  // Don't forget to save the result!
    
    waitKey();
    return 0;
}

教程三:

int sample(mglGraph *gr)
{
  mglData y0(50); 	y0.Modify("sin(pi*(2*x-1))");
  gr->SubPlot(2,2,0);
  gr->Plot(y0);   	gr->Box();
  gr->SubPlot(2,2,1);
  mglData y1(50,2);
  y1.Modify("sin(pi*2*x-pi)");
  y1.Modify("cos(pi*2*x-pi)/2",1);
  gr->Plot(y1);   	gr->Box();

  mglData x(50);  	x.Modify("cos(pi*2*x-pi)");
  gr->Plot(x,y0,"Y+");

  gr->Plot(y1.SubData(-1,0),y1.SubData(-1,1),"q|");
  gr->SubPlot(2,2,2);	gr->Rotate(60,40);
  mglData z(50);  	z.Modify("2*x-1");
  gr->Plot(x,y0,z);	gr->Box();

// Functions plot and subdata make 3D curve plot but for single array. Use it to put circle marks on the previous plot:
  mglData y2(10,3);	y2.Modify("cos(pi*(2*x-1+y))");
  y2.Modify("2*x-1",2);
  gr->Plot(y2.SubData(-1,0),y2.SubData(-1,1),y2.SubData(-1,2),"bo ");
// Note that line style is empty ‘ ’ here. Usage of other 1D plotting functions looks similar:
  gr->SubPlot(2,2,3);	gr->Rotate(60,40);
  gr->Bars(x,y0,z,"r");	gr->Box();
  return 0;
}

 5.2 看源码中的example——没看出来名堂

exe在mgltask中,放运行库dll的位置。
mgl_example.exe中放入libpng.dll和zlib.dll 
运行mgl_example,命令行输出如下图所示,不知道到底在执行哪些test。

二、其它出现的问题

2.1 动态库、静态库、Release、Debug

 2.2 error LNK2038: 检测到“RuntimeLibrary”的不匹配项的解决办法

error LNK2038: 检测到“RuntimeLibrary”的不匹配项的解决办法_阳光柠檬_的技术笔记-CSDN博客_lnk2038

    动态库和静态库是不能同时使用的。必须一致!!!!!!!!!

2.3 无法解析的外部符号 __std_reverse_trivially_swappable_4 

记录一些编程过程中遇到的乱七八糟的问题_yacoxy的博客-CSDN博客_在编程过程中遇到的问题

据说是编译器版本不匹配原因导致的。 

 但是v14.1是vs2017才有的!

没法弄!

2.3.1 最终升级到VS2019解决这个问题

VS14.0无法编译成功MathGLC,要至少VS2017以上才行。 

三、MathGL库的使用

  3.1 数据类型mglData认识

 3.1.1 MathGL的数据结构 Data constructor(来自MathGL doc)

mglData

  1.  mglData数据结构:支持float、double、int、char等类型的一维数组、二维数组。支持三种类型的vector。
  2. 数据存在实数矩阵a中,做

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值