c - c 中的基本 MathGL 示例无法编译
问题描述
这是文档中的基本 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 标题之前,并在此之前确保你#include <stdbool.h>
. 此外,当您使用例如与 Qt 相关的函数时,请确保#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++ - 无法通过 C++ 中的引用捕获抛出的异常
- qt - 如何使用 msvc 2019 编译 QT 4 dll?
- symfony - 将 parameters.yml 值传递给 Akeneo 前端
- javascript - javascript 强制 ASP.NET 表单重新加载与 JQuery 自动完成文本框填充冲突?
- r - 在 R 中应用逐行转换,以便每行的总百分比为 100%
- java - 使用 Dagger2 Android 刷新 Oauth2
- laravel - 如何在没有 npm 的情况下安装 laravel/breeze?
- git - 合并没有引入合并的更改
- php - 如何修复 laravel 表单提交?
- python - “消息”对象没有属性“用户”