Mac安装NTL库

Mac安装NTL库

NTL是一个高性能、可移植的C++库,为任意长度的整数提供数据结构和算法;用于整数和有限域上的向量、矩阵和多项式;以及任意精度的浮点运算。

具有以下功能:

  • 任意长度整数运算和任意精度浮点运算;

  • 整数和有限域上的多项式算术,包括基本算术、多项式分解、不可约判定、最小多项式计算、迹线、范数等计算;

  • 格基归约,包括 非常健壮和快速的Schnorr-Euchner,实现、块 Korkin-Zolotarev 归约,以及块 Korkin-Zolotarev 的新 Schnorr-Horner 剪枝启发式;

  • 整数、有限域和任意精度浮点数的基本线性代数。

NTL同时具备Unix、Mac OS或Windows任意平台上使用,NTL可与GMP一起构建以增强性能,NTL可与GF2X库一起构建,以便在GF(2)上快速计算大型多项式

安装环境:

macOS-M1-8核

GMP安装

GMP是一个用于长整数运算的库,对于基本运算(例如整数乘法),它比NTL的长整数快2-3倍,因此NTL库默认使用GMP库,所以安装NTL库之前首先安装GMP库。

  • 下载

官网:https://gmplib.org/

为了便于在Mac下解压缩,建议下载tar.xz版本

image-20221003144911408

  • 编译&安装
cd gmp-6.2.1

./configure --enable-cxx  # 默认安装在/usr/local,在使用configure的时候要加上 --enable-cxx命令,否则不能使用c++库gmpxx.h

make -j8

make install

image-20221003145229565

NTL安装

  • 下载

地址:https://libntl.org/download.html

image-20221003153826278

  • 编译&安装
./configure  NTL_GMP_LIP=on

make

sudo make install

image-20221003155257752

  • 测试
#include <iostream>
#include <NTL/ZZ.h>

using namespace std;
using namespace NTL;

int main(){
    ZZ a(1);
    cout << a << endl;
}


//cmakelists.txt
cmake_minimum_required(VERSION 3.23)
project(untitled)

set(CMAKE_CXX_STANDARD 14)

include_directories(/usr/local/include)
link_directories(/usr/local/lib)

add_executable(untitled main.cpp)
target_link_libraries(untitled libntl.a libgmp.a)

参考

1、https://blog.csdn.net/qq_38798147/article/details/126700646

2、https://blog.csdn.net/zha_ojunchen/article/details/89818011

posted @ 2022-10-03 16:03  PamShao  阅读(544)  评论(0编辑  收藏  举报