如何在Qt-Creator中正确使用mpfr / gmp?

问题描述 投票:1回答:1

您好,我想使用Qt-creator创建一个Qt5项目,并想使用mpfr / gmp,所以我需要如何配置该项目。

因为如果我编译,我会得到这些错误:

#include "mainwindow.h"

#include <QApplication>
#include <stdio.h>
#include <gmp.h>
#include <mpfr.h>



int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    MainWindow w;
    w.show();

    mpfr_t x, y, z, t;
    mpfr_inits2 (256, x, y, z, t, (mpfr_ptr) 0);

    return a.exec();
}

输出:

 error: undefined reference to `mpfr_inits2'

但是在代码块上,我添加了包含路径和库路径,并向编译器添加了标志-lgmp -lmpfr,并且可以正常工作。

c++ qt-creator mpfr
1个回答
0
投票

在QtCreator中,打开项目的.pro文件并添加以下行:

unix: LIBS += -lmpfr -lgmp

或者,您也可以使用UI来执行此操作:在“项目”列表中,右键单击您的项目,选择“添加库”>“系统库”。在“库文件”字段中添加例如/usr/lib/mpfr.so。然后,如“摘要”视图中所示,QtCreator将其转换为-lmpfr。重复这些步骤以添加/usr/lib/libgmp.so

enter image description hereenter image description here

© www.soinside.com 2019 - 2024. All rights reserved.