MPFR:未定义参考| 安装不正确?

乡村

我正在尝试在Ubuntu 20.04上使用mpfr库。

我已经安装了:

sudo apt-get install -y libmpfr-dev libmpfr6

我有一个简单的测试代码(从某处的教程复制):

#include <iostream>
#include <mpfr.h>

int main() {
    mpfr_t s, t;
    mpfr_init2(s, 2000);
    mpfr_set_d(s, 22, MPFR_RNDD);
    mpfr_init2(t, 2000);
    mpfr_set_d(t, 7, MPFR_RNDD);
    mpfr_div(s, s, t, MPFR_RNDD);
    mpfr_out_str(stdout, 10, 0, s, MPFR_RNDD);
    std::cout << std::endl;
    mpfr_clear(s);
    mpfr_clear(t);
    mpfr_free_cache();
}

它看起来像是C代码,但这只是一个玩具示例。在实际程序中,它将是一个C++代码,因此我使用cpp扩展和g++编译器。

我用它编译:

g++ -O0 -Wall --std=c++14 -L/usr/lib -lmpfr -lgmp -o test test.cpp

而且我收到错误消息,好像缺少库定义文件...

/usr/bin/ld: /tmp/cc1XbFhH.o: in function `main':
test.cpp:(.text+0x28): undefined reference to `mpfr_init2'
/usr/bin/ld: test.cpp:(.text+0x45): undefined reference to `mpfr_set_d'
/usr/bin/ld: test.cpp:(.text+0x56): undefined reference to `mpfr_init2'
/usr/bin/ld: test.cpp:(.text+0x73): undefined reference to `mpfr_set_d'
/usr/bin/ld: test.cpp:(.text+0x8c): undefined reference to `mpfr_div'
/usr/bin/ld: test.cpp:(.text+0xb2): undefined reference to `__gmpfr_out_str'
/usr/bin/ld: test.cpp:(.text+0xd4): undefined reference to `mpfr_clear'
/usr/bin/ld: test.cpp:(.text+0xe0): undefined reference to `mpfr_clear'
/usr/bin/ld: test.cpp:(.text+0xe5): undefined reference to `mpfr_free_cache'
collect2: error: ld returned 1 exit status

我做错了吗?我知道图书馆有:

$ dpkg -L libmpfr6
/.
/usr
/usr/lib
/usr/lib/x86_64-linux-gnu
/usr/lib/x86_64-linux-gnu/libmpfr.so.6.0.2
/usr/share
/usr/share/doc
/usr/share/doc/libmpfr6
/usr/share/doc/libmpfr6/AUTHORS
/usr/share/doc/libmpfr6/BUGS
/usr/share/doc/libmpfr6/NEWS.gz
/usr/share/doc/libmpfr6/README
/usr/share/doc/libmpfr6/TODO.gz
/usr/share/doc/libmpfr6/changelog.Debian.gz
/usr/share/doc/libmpfr6/copyright
/usr/lib/x86_64-linux-gnu/libmpfr.so.6
$ dpkg -L libmpfr-dev
/.
/usr
/usr/include
/usr/include/mpf2mpfr.h
/usr/include/mpfr.h
/usr/lib
/usr/lib/x86_64-linux-gnu
/usr/lib/x86_64-linux-gnu/libmpfr.a
/usr/lib/x86_64-linux-gnu/pkgconfig
/usr/lib/x86_64-linux-gnu/pkgconfig/mpfr.pc
/usr/share
/usr/share/doc
/usr/share/doc/libmpfr-dev
/usr/share/doc/libmpfr-dev/copyright
/usr/lib/x86_64-linux-gnu/libmpfr.so
/usr/share/doc/libmpfr-dev/AUTHORS
/usr/share/doc/libmpfr-dev/BUGS
/usr/share/doc/libmpfr-dev/NEWS.gz
/usr/share/doc/libmpfr-dev/README
/usr/share/doc/libmpfr-dev/TODO.gz
/usr/share/doc/libmpfr-dev/changelog.Debian.gz
/usr/share/doc/libmpfr-dev/changelog.gz
萨米·库莫宁(Sami Kuhmonen)

问题出在编译命令行中。论据的顺序很重要:依赖他人的事物必须于他们依赖的事物。因此,如果您使用此命令

g++ -O0 -Wall --std=c++14 -L/usr/lib -o asd asd.cpp -lmpfr -lgmp

由于库位于需要它们的源代码之后因此编译将成功

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

未定义的索引不正确

来自分类Dev

变量定义不正确

来自分类Dev

访问Perl Hash的未定义值时,初始化不正确

来自分类Dev

未定义的rspec方法,可能要求不正确?

来自分类Dev

“来自findAll的响应必须是数组,而不是未定义的”-潜在的不正确序列化?

来自分类Dev

链接不正确,函数未定义,Eclipse GCC库路径

来自分类Dev

APP_ROOT定义不正确

来自分类Dev

scilab子矩阵定义不正确

来自分类Dev

Laravel迁移不正确的表定义

来自分类Dev

JAVA_HOME定义不正确

来自分类Dev

$作用域定义不正确

来自分类Dev

APP_ROOT定义不正确

来自分类Dev

vuejs 组件定义不正确

来自分类Dev

不正确的成员构造函数定义

来自分类Dev

Virtualenvwrapper安装不正确

来自分类Dev

Vundle安装不正确

来自分类Dev

Xamarin安装不正确

来自分类Dev

PHP array_unique结果发现不正确的重复,以及如何摆脱未定义的偏移量?

来自分类Dev

前向参考不正确的有趣问题

来自分类Dev

Firebase Cloud Function更新参考值不正确

来自分类Dev

前向参考不正确的有趣问题

来自分类Dev

服务参考生成不正确的方法签名

来自分类Dev

leafletjs自定义标记位置不正确

来自分类Dev

Ruby“定义了吗?” 运算符工作不正确?

来自分类Dev

C ++ CMenu绘制不正确(非自定义)

来自分类Dev

自定义复选框不正确

来自分类Dev

Jekyll自定义变量输出不正确的值

来自分类Dev

类定义不正确。需要标识符

来自分类Dev

参数对象定义不正确vb.net mariadb