c 中的基本 MathGL 示例无法编译
Basic MathGL example in c does not compile
这是文档中的基本 C 示例:
#include <mgl2/mgl_cf.h>
int sample(HMGL gr, void *)
{
mgl_rotate(gr,60,40,0);
mgl_box(gr);
}
int main(int argc,char **argv)
{
HMGL gr;
gr = mgl_create_graph_qt(sample,"MathGL examples",0,0);
return mgl_qt_run();
/* generally I should call mgl_delete_graph() here,
* but I omit it in main() function. */
}
这里是编译输出的开始:
$ gcc test.c -lmgl-qt5 -lmgl
In file included from /usr/include/mgl2/mgl_cf.h:29,
from test.c:1:
/usr/include/mgl2/data_cf.h:527:17: error: expected ‘,’ or ‘;’ before ‘mgl_find_roots’
527 | bool MGL_EXPORT mgl_find_roots(size_t n, void (*func)(const mreal *x, mreal *f, void *par), mreal *x0, void *par);
| ^~~~~~~~~~~~~~
test.c: In function ‘sample’:
test.c:2:21: error: parameter name omitted
2 | int sample(HMGL gr, void *)
| ^~~~~~
我很清楚这个例子甚至不是有效的 c,缺少 sample() 函数的一个参数(实际上没有使用)。我已经尝试删除它,但仍然遇到第一个(内部 mathgl)错误。
知道如何进行吗?
MathGL 似乎没有按顺序排列其内部 #include
语句,需要您注意 #include
的内容和顺序。特别是,确保您 #include <mgl2/mgl.h>
在任何其他 MathGL header 之前,并在此之前确保您 #include <stdbool.h>
。此外,当您使用 Qt-related 函数时,请确保您 #include <mgl2/qt.h>
。这应该有效:
#include <stdbool.h>
#include <mgl2/mgl.h>
#include <mgl2/qt.h>
int sample(HMGL gr, void *ignored)
{
mgl_rotate(gr,60,40,0);
mgl_box(gr);
}
int main(int argc, char **argv)
{
HMGL gr = mgl_create_graph_qt(sample, "MathGL examples", 0, 0);
return mgl_qt_run();
}
这是文档中的基本 C 示例:
#include <mgl2/mgl_cf.h>
int sample(HMGL gr, void *)
{
mgl_rotate(gr,60,40,0);
mgl_box(gr);
}
int main(int argc,char **argv)
{
HMGL gr;
gr = mgl_create_graph_qt(sample,"MathGL examples",0,0);
return mgl_qt_run();
/* generally I should call mgl_delete_graph() here,
* but I omit it in main() function. */
}
这里是编译输出的开始:
$ gcc test.c -lmgl-qt5 -lmgl
In file included from /usr/include/mgl2/mgl_cf.h:29,
from test.c:1:
/usr/include/mgl2/data_cf.h:527:17: error: expected ‘,’ or ‘;’ before ‘mgl_find_roots’
527 | bool MGL_EXPORT mgl_find_roots(size_t n, void (*func)(const mreal *x, mreal *f, void *par), mreal *x0, void *par);
| ^~~~~~~~~~~~~~
test.c: In function ‘sample’:
test.c:2:21: error: parameter name omitted
2 | int sample(HMGL gr, void *)
| ^~~~~~
我很清楚这个例子甚至不是有效的 c,缺少 sample() 函数的一个参数(实际上没有使用)。我已经尝试删除它,但仍然遇到第一个(内部 mathgl)错误。
知道如何进行吗?
MathGL 似乎没有按顺序排列其内部 #include
语句,需要您注意 #include
的内容和顺序。特别是,确保您 #include <mgl2/mgl.h>
在任何其他 MathGL header 之前,并在此之前确保您 #include <stdbool.h>
。此外,当您使用 Qt-related 函数时,请确保您 #include <mgl2/qt.h>
。这应该有效:
#include <stdbool.h>
#include <mgl2/mgl.h>
#include <mgl2/qt.h>
int sample(HMGL gr, void *ignored)
{
mgl_rotate(gr,60,40,0);
mgl_box(gr);
}
int main(int argc, char **argv)
{
HMGL gr = mgl_create_graph_qt(sample, "MathGL examples", 0, 0);
return mgl_qt_run();
}