• <li id="00i08"><input id="00i08"></input></li>
  • <sup id="00i08"><tbody id="00i08"></tbody></sup>
    <abbr id="00i08"></abbr>
  • 博客專欄

    EEPW首頁 > 博客 > 在Ubuntu上安裝NTL庫以及編譯測試

    在Ubuntu上安裝NTL庫以及編譯測試

    發(fā)布人:電子禪石 時間:2024-09-09 來源:工程師 發(fā)布文章

    這篇文章是21年第一次安裝的時候?qū)懙? 24年換電腦又需要重裝一遍, 還是按照這個做的, 

    連錯誤都一模一樣. 只要按順序做就能夠安裝成功.


    介紹:

    NTL是一個高性能的,可移植的c++庫,提供任意長度整數(shù)的數(shù)據(jù)結(jié)構(gòu)和算法;


    于整數(shù)和有限域上的向量、矩陣和多項式;并且適用于任意精度的浮點運算。

    我們在Ubuntu中進行安裝. (我使用的是Windows下的子系統(tǒng)wsl,但是應(yīng)該是一樣的)


    步驟:

    0. 下載前的準備

    首先我們要確保必須有g(shù)++ 和 m4

    g++: sudo apt install g++

    m4: sudo apt install m4

    確認安裝:g++ -v 和m4 --v

    ————————————————


    3. 對GMP進行編譯

    首先我們把剛剛下載好的放到一起嗷。如下圖所示:

    然后進入gmp這個文件夾
    一條一條依次輸入

    ./configure
    
    make
    
    make check
    
    sudo make install

    這一步應(yīng)該不存在問題,正確編譯后:
    輸入ls /usr/local/include/ 會看到gmp.h

    輸入ls /usr/local/lib/ 會看到一些這樣子的文件(我的可能多一些,因為我是兩個實驗做完截的圖)

    ls /usr/local/lib/
    libgmp.a   libgmp.so     libgmp.so.10.5.0   libmosquittopp.so.1  libmosquitto.so.1  python2.7
    libgmp.la  libgmp.so.10  libmosquittopp.so  libmosquitto.so      pkgconfig          python3.5
    4. 對NTL進行編譯

    我們進入ntl的文件夾中的src文件夾中,然后重復(fù)上面的指令:

    ./configure
    
    make
    
    make check
    
    sudo make install

    ATTENTION:這里在make過程中可能會出錯,下圖是我的報錯提示

    *** Checking for feature: COPY_TRAITS1 [yes]
    *** Checking for feature: COPY_TRAITS2 [yes]
    *** Checking for feature: CHRONO_TIME [yes]
    *** Checking for feature: MACOS_TIME [no]
    *** Checking for feature: POSIX_TIME [yes]
    *** Checking for feature: AES_NI [yes]
    *** Checking for feature: KMA [no]
    make[1]: Leaving directory '/mnt/hgfs/gitLab/ntl-11.5.1/src'
    make setup3
    make[1]: Entering directory '/mnt/hgfs/gitLab/ntl-11.5.1/src'
    g++ -I../include -I.  -g -O2 -std=c++11 -pthread -march=native   -o gen_gmp_aux gen_gmp_aux.cpp  -lgmp  -lm
    ./gen_gmp_aux > ../include/NTL/gmp_aux.h 
    NTL_GMP_LIP flag set
    GMP version check (6.3.0/6.1.0)
    *** version number mismatch: inconsistency between gmp.h and libgmp
    /bin/sh: line 1: 44940 Aborted                 (core dumped) ./gen_gmp_aux > ../include/NTL/gmp_aux.h
    makefile:360: recipe for target 'setup3' failed
    make[1]: *** [setup3] Error 134
    make[1]: Leaving directory '/mnt/hgfs/gitLab/ntl-11.5.1/src'
    makefile:324: recipe for target 'setup-phase' failed
    make: *** [setup-phase] Error 2

    我們看到說version number mismatch這一行是我們的出錯原因。
    這里我參考了 這個網(wǎng)站 中的某個回答,輸入sudo ldconfig, 把新安裝的gmp庫更新下即可解決此問題。

    Version number mismatch: inconsistency between gmp.h and libgmp - Stack Overflow

    https://stackoverflow.com/questions/50046463/version-number-mismatch-inconsistency-between-gmp-h-and-libgmp


    關(guān)于sudo ldconfig
    之后應(yīng)該順利進行了,成功后如下圖所示:

    ls /usr/local/include/
    gmp.h  mosquitto.h  mosquitto_plugin.h  mosquittopp.h  nlohmann  NTL

    編譯測試:

    源文件test.cpp:

    #include <NTL/ZZ.h>
    
    using namespace std;
    using namespace NTL;
    
    int main()
    {
       ZZ a, b, c;
    
       cin >> a;
       cin >> b;
       c = (a+1) * (b+1);
       cout << c << "\n";
    }

    在命令行輸入:

    g++ test.cpp -o test.exe -lntl -pthread -lgmp

    就可以生成test可執(zhí)行文件,執(zhí)行即可。

    關(guān)于wsl下載和文件權(quán)限:

    關(guān)于wsl下載的一些事:

    如果把在Windows里下載解壓好的文件夾拖入Ubuntu中,會發(fā)生權(quán)限問題,

    拖入的文件甚至連訪問都不可以,需要使用chmod -r 777 file_name指令去加權(quán)限

    (使用-r,因為需要遞歸地改變,子文件也是都需要改的)。

    那比較簡單的替代方法就是在Windows中解壓后,在Ubuntu中使用cp指令復(fù)制一個過去

    (Windows磁盤掛載在mnt/中),這樣權(quán)限不會發(fā)生問題。


    參考資料:

    https://stackoverflow.com/questions/42607099/installing-ntl-with-gmp

    https://libntl.org/doc/tour.html(選項5,9)

    https://stackoverflow.com/questions/50046463/version-number-mismatch-inconsistency-between-gmp-h-and-libgmp

    https://zhuanlan.zhihu.com/p/66102855

    ————————————————


                            

    原文鏈接:https://blog.csdn.net/weixin_45599342/article/details/121293041



                            


    *博客內(nèi)容為網(wǎng)友個人發(fā)布,僅代表博主個人觀點,如有侵權(quán)請聯(lián)系工作人員刪除。



    關(guān)鍵詞: ntl

    技術(shù)專區(qū)

    關(guān)閉
    主站蜘蛛池模板: 安阳市| 江安县| 民权县| 海伦市| 迁安市| 漾濞| 谢通门县| 渝北区| 阆中市| 碌曲县| 安乡县| 隆子县| 天等县| 绥滨县| 峨边| 满城县| 湟中县| 视频| 蒙阴县| 吉水县| 鄂托克旗| 九江县| 上林县| 阳原县| 娄底市| 张北县| 寿宁县| 万宁市| 忻城县| 武乡县| 巴彦县| 兴隆县| 山阴县| 孟连| 富宁县| 辽宁省| 通山县| 西乌| 商丘市| 陇川县| 古浪县|