在Ubuntu上安裝NTL庫(kù)以及編譯測(cè)試
這篇文章是21年第一次安裝的時(shí)候?qū)懙? 24年換電腦又需要重裝一遍, 還是按照這個(gè)做的,
連錯(cuò)誤都一模一樣. 只要按順序做就能夠安裝成功.
介紹:
NTL是一個(gè)高性能的,可移植的c++庫(kù),提供任意長(zhǎng)度整數(shù)的數(shù)據(jù)結(jié)構(gòu)和算法;
對(duì)
于整數(shù)和有限域上的向量、矩陣和多項(xiàng)式;并且適用于任意精度的浮點(diǎn)運(yùn)算。
我們?cè)赨buntu中進(jìn)行安裝. (我使用的是Windows下的子系統(tǒng)wsl,但是應(yīng)該是一樣的)
步驟:
0. 下載前的準(zhǔn)備
首先我們要確保必須有g(shù)++ 和 m4
g++: sudo apt install g++
m4: sudo apt install m4
確認(rèn)安裝:g++ -v 和m4 --v
————————————————
然后進(jìn)入gmp這個(gè)文件夾
一條一條依次輸入
./configure make make check sudo make install
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.54. 對(duì)NTL進(jìn)行編譯
./configure make make check sudo make install
ATTENTION:這里在make過(guò)程中可能會(huì)出錯(cuò),下圖是我的報(bào)錯(cuò)提示
*** 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
我們看到說(shuō)version number mismatch這一行是我們的出錯(cuò)原因。
這里我參考了 這個(gè)網(wǎng)站 中的某個(gè)回答,輸入sudo ldconfig, 把新安裝的gmp庫(kù)更新下即可解決此問(wèn)題。
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)該順利進(jìn)行了,成功后如下圖所示:
ls /usr/local/include/ gmp.h mosquitto.h mosquitto_plugin.h mosquittopp.h nlohmann NTL
編譯測(cè)試:
#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里下載解壓好的文件夾拖入U(xiǎn)buntu中,會(huì)發(fā)生權(quán)限問(wèn)題,
拖入的文件甚至連訪問(wèn)都不可以,需要使用chmod -r 777 file_name指令去加權(quán)限
(使用-r,因?yàn)樾枰f歸地改變,子文件也是都需要改的)。
那比較簡(jiǎn)單的替代方法就是在Windows中解壓后,在Ubuntu中使用cp指令復(fù)制一個(gè)過(guò)去
(Windows磁盤掛載在mnt/中),這樣權(quán)限不會(huì)發(fā)生問(wèn)題。
參考資料:
https://stackoverflow.com/questions/42607099/installing-ntl-with-gmp
https://libntl.org/doc/tour.html(選項(xiàng)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)友個(gè)人發(fā)布,僅代表博主個(gè)人觀點(diǎn),如有侵權(quán)請(qǐng)聯(lián)系工作人員刪除。