博客專欄

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

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

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

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

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


        介紹:

        NTL是一個高性能的,可移植的c++庫,提供任意長度整數的數據結構和算法;


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

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


        步驟:

        0. 下載前的準備

        首先我們要確保必須有g++ 和 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

        這一步應該不存在問題,正確編譯后:
        輸入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文件夾中,然后重復上面的指令:

        ./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這一行是我們的出錯原因。
        這里我參考了 這個網站 中的某個回答,輸入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


        關于sudo ldconfig
        之后應該順利進行了,成功后如下圖所示:

        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可執行文件,執行即可。

        關于wsl下載和文件權限:

        關于wsl下載的一些事:

        如果把在Windows里下載解壓好的文件夾拖入Ubuntu中,會發生權限問題,

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

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

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

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


        參考資料:

        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



                                


        *博客內容為網友個人發布,僅代表博主個人觀點,如有侵權請聯系工作人員刪除。



        關鍵詞: ntl

        技術專區

        關閉
        主站蜘蛛池模板: 涪陵区| 石城县| 油尖旺区| 缙云县| 澎湖县| 云梦县| 子洲县| 丰镇市| 徐闻县| 旬邑县| 房产| 望都县| 天祝| 长白| 射洪县| 工布江达县| 包头市| 石楼县| 新闻| 攀枝花市| 怀集县| 休宁县| 大港区| 灵台县| 鲁山县| 图片| 宜良县| 海阳市| 彭水| 衡南县| 社会| 莲花县| 噶尔县| 宣化县| 焦作市| 眉山市| 喀什市| 托克逊县| 肃宁县| 和平区| 涞水县|