【发布时间】:2018-04-17 14:36:16
【问题描述】:
我正在使用带有 gcc 的 Cygwin,我正在尝试运行一个使用 mpfr 库的快速示例程序,并且我有这行代码:
mpfr_out_str (stdout, 10, 0, s, MPFR_RNDD);
我收到了这个编译器警告。
main.c: In function ‘main’:
main.c:21:5: warning: implicit declaration of function ‘mpfr_out_str’; did you mean ‘mpf_out_str’? [-Wimplicit-function-declaration]
mpfr_out_str (stdout, 10, 0, s, MPFR_RNDD);
^~~~~~~~~~~~
mpf_out_str
然而,当我在网上查看各种网站以获取简单的使用示例时,甚至查看了他们都在使用的 mpfr 文档
mpfr_out_str(...)
...
那么为什么编译器向我抱怨我应该使用
mpf_out_str
相反?
--- main.c --- online example
#include <stdio.h>
#include "gmp.h"
#include "mpfr.h"
int main() {
unsigned int i;
mpfr_t s, t, u;
mpfr_init2 (t, 200);
mpfr_set_d (t, 1.0, MPFR_RNDD);
mpfr_init2 (s, 200);
mpfr_set_d (s, 1.0, MPFR_RNDD);
mpfr_init2 (u, 200);
for ( i = 1; i <= 100; i++ ) {
mpfr_mul_ui (t, t, i, MPFR_RNDU);
mpfr_set_d (u, 1.0, MPFR_RNDD);
mpfr_div (u, u, t, MPFR_RNDD);
mpfr_add (s, s, t, MPFR_RNDD);
}
printf( "Sum is " );
mpfr_out_str (stdout, 10, 0, s, MPFR_RNDD); // this line here
putchar ('\n');
mpfr_clear(s);
mpfr_clear(t);
mpfr_clear(u);
return 0;
}
另外出于某种原因,我认为带有 gcc 的 Cygwin 在链接 gmp 和 mprf 时遇到问题...我使用的是 gcc 版本 7.3.0 (GCC)。
注意:在我的 main.c 中,我最初的包含与在线示例相同:
#include <...>
我之前提到我在链接库时遇到了问题,并尝试了数百种不同的方法来尝试链接它们,这里无法列出。因此,最终我复制了库及其标头,并将它们直接粘贴到包含 main.c 的同一文件夹中,这就是为什么您将我的包含视为
#include "..."
而不是原始的在线示例。
请注意,对于在使用 gcc/g++ 或 clang 的 Unix 环境中编译 c/c++ 代码的 Unix-POSIX 环境、操作或命令行参数,我并不十分熟悉。我主要习惯于 Visual Studio、windows 和 cmd 以及它的功能、设置和语法。现在我正在从文档、网站、在线教程(包括文本和视频等)中学习。
这可能是另一个问题的讨论主题,但我认为它可能与部分回答此发布的问题有关。
当一个人安装 Cygwin 然后决定安装 gcc/g++ 而不是 mingw 的 clang;应该已经安装了 gmp 和 mpir 还是必须手动安装它们?如果是:按什么顺序? gmp & mpir 需要在 gcc 之前安装还是可以在之后安装?该命令对 gcc 如何能够链接到此类库有影响吗?正确的安装顺序和库链接能否解决此编译器警告?
【问题讨论】:
-
你加入了
#include <mpfr.h>吗? -
你是
#include <gmp.h>和#include <mpfr.h>吗? -
测试这个示例代码:mpfr.org/sample.html
-
如果缺少包含,那么它是重复的。
-
OP 没有反应,所以这可能是问题所在。我要关闭这个。如果是其他问题,请随时联系我。
标签: c gcc cygwin gcc-warning mpfr