I'm trying to compile the first example of the MathGL library in C:
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);
}
I installed libmgl-dev using aptitude and rejected the first option offered, because aptitude wanted to remove a number of different programs and accepted the second option, which only upgraded a few.
If I try to compile:
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);
So I tried to add #include <stdbool.h>
and tried flags like -std=gnu11
or -std=c11
and -std=c99
. None of which worked. I tried adding the flag -lmgl
(I even read that I should put it at the very end).
How do I compile this example?
You appear to have an old version of the library, in which this is a bug.
See this bug report from May 2013. The Alexey Balakin who confirms the bug is the lead developer of MathGL.
See that the bug is fixed in MathGL 2.3.3 version of data_ch.h, where the declaration is:
void MGL_EXPORT mgl_fft(double *x, long s, long n, const void *wt, void *ws, int inv);
with bool
replaced by int
.