首先去官網下載安裝包,下列shell腳本與安裝包放到同一目錄,賦予此腳本執行權限。另外,我這里默認你的電腦上面已經安裝gcc,g++,make。
#apt install -y gcc
#apt install -y g++
#apt install -y make
apt install -y autoconf
apt install -y m4
apt install -y libgmp-dev
apt install -y libgf2x-dev
tar zxvf ntl-11.4.3.tar.gz
mv ntl-11.4.3 ntl
echo -e "\033[31m start install ntl \033[0m"
cd ntl/src
./configure NTL_GF2X_LIB=on
make && make check && make install
cd - >> /dev/null
rm -r ntl
測試一下:新建一個rand.cpp(顧名思義,是輸出隨機數)
#include <NTL/ZZ.h>
#include <time.h>
NTL_CLIENT
int main()
{
ZZ a,b,c;
SetSeed(to_ZZ(time(NULL)));
RandomLen(a, 32);
RandomLen(b, 32);
c = a + b;
cout << "a=" << a << ", b=" << b << ", c=" << c << "\n";
return 0;
}
按照官網的介紹,使用如下命令編譯:
g++ -g -O2 -std=c++11 -pthread -march=native rand.cpp -o rand -lntl -lgmp -lm
其中rand.cpp是c++文件,rand是編譯后的可執行文件。程序運行效果如下:
$ ./rand
a=2298665095, b=3622090486, c=5920755581
參考鏈接:
NTL庫快速上手中文指南
A Tour of NTL