编译 mathgl C 示例

Compiling mathgl C-Example

我正在尝试用 C:

编译 MathGL 库的第一个示例

http://mathgl.sourceforge.net/doc_en/Examples.html

#include <mgl2/mgl_cf.h>

int main()
{
  HMGL gr = mgl_create_graph(600,400);
  mgl_fplot(gr,"sin(pi*x)","","");
  mgl_write_frame(gr,"test.png","");
  mgl_delete_graph(gr);
}

我使用 aptitude 安装了 libmgl-dev 并拒绝了提供的第一个选项,因为 aptitude 想要删除许多不同的程序并接受了第二个选项,它只升级了几个。

如果我尝试编译:

gcc test.c  -o test -lmgl
In file included from /usr/include/mgl2/mgl_cf.h:29:0,
                 from test.c:1:
/usr/include/mgl2/data_cf.h:318:78: error: unknown type name ‘bool’
 EXPORT mgl_fft(double *x, long s, long n, const void *wt, void *ws, bool inv);

所以我尝试添加 #include <stdbool.h> 并尝试使用 -std=gnu11-std=c11-std=c99 等标志。 None 其中有效。我尝试添加标志 -lmgl(我什至读到我应该把它放在最后)。

如何编译这个例子?

你似乎有一个旧版本的库,这是一个错误。

看到这个bug report 从 2013 年 5 月开始。确认该错误的 Alexey Balakin 是 MathGL 的首席开发人员。

看到该错误已在 data_ch.h 的 MathGL 2.3.3 版本中修复, 声明是:

void MGL_EXPORT mgl_fft(double *x, long s, long n, const void *wt, void *ws, int inv);

bool 替换为 int