[Previous] [Up] [Next]

A Tour of NTL: Obtaining and Installing NTL for UNIX

This procedure should work on most Unix or Unix-like platorms (including Mac OSX, and Windows with Cygwin tools).

To obtain the source code and documentation for NTL, download ntl-xxx.tar.gz, placing it a directory, and then, working in this directory, do the following. Here, "xxx" denotes the current version number.

   % gunzip ntl-xxx.tar.gz
   % tar xf ntl-xxx.tar
   % cd ntl-xxx/src
   % ./configure PREFIX=$HOME/sw
   % make
   % make check
   % make install
This will build, test, and install NTL in $HOME/sw. Of course, change $HOME/sw to whatever you want (the default is /usr/local). You will find the NTL header files in $HOME/sw/include/NTL and the compiled binary in $HOME/sw/lib/libntl.a (this is a static library -- if you want a shared library, see below).

If you really are interested in high-performace, you will definitely want to build NTL using GMP (the GNU Multi-Precision package). If GMP has already been installed in a standard place, like /usr/local, then invoke configure above as

   % ./configure PREFIX=$HOME/sw NTL_GMP_LIP=on
and if GMP is installed somewhere else, say $HOME/sw, then either
   % ./configure PREFIX=$HOME/sw NTL_GMP_LIP=on GMP_PREFIX=$HOME/sw
or, more simply,
   % ./configure DEF_PREFIX=$HOME/sw NTL_GMP_LIP=on 
does the job. Here, DEF_PREFIX is a variable that is used to specify the location of all software, and it defaults to /usr/local. This page provides more details.

If you want very high-performance for polynomial arithmetic over GF(2), you may want to consider using the gf2x library. To do this, gf2x must already be installed somewhere. In addition, you should invoke configure with the option NTL_GF2X_LIB=on. If gf2x is installed in a standard location, this is all you need to do; otherwise, if gf2x is installed, say, in $HOME/sw, then you also need to pass the option GF2X_PREFIX=$HOME/sw. This page provides more details.

Even if you don't want to experiment with the gf2x library, you might want to try setting NTL_PCLMUL=on, which will enable the use special hardware support for fast polynomial arithmetic over GF(2) on platforms that support it (the configure script will check that it actually works). You can set NTL_PCLMUL=on even if you also set NTL_GF2X_LIB=on, but it probably won't help much.

Now suppose you want to compile a program that uses NTL. Suppose you are working in some directory and foo.c is your program. Assume that you have installed NTL in $HOME/sw as above. The following should work:

   % g++  -I$HOME/sw/include foo.c -o foo  -L$HOME/sw/lib -lntl  -lm
If you are using GMP, then:
   % g++ -I$HOME/sw/include foo.c -o foo  -L$HOME/sw/lib -lntl -lgmp  -lm
If you are using GMP and gf2x, then
   % g++  -I$HOME/sw/include foo.c -o foo  -L$HOME/sw/lib -lntl -lgmp -lgf2x  -lm

More Details

What follows is a more detailed description of the installation process.

Step 1. Extract the source files by executing:

   % gunzip ntl-xxx.tar.gz
   % tar xvf ntl-xxx.tar

Note that this will unpack everything into a sub-directory ntl-xxx, creating this directory if necessary. Next:

   % cd ntl-xxx
   % ls
You should see a file "README", and directories "include", "doc", and "src". The directory "doc" contains all the documentation. The file "doc/tour.html" contains a copy of the on-line documentation. The directory "include" contains all the header files within a subdirectory "include/NTL". The directory "src" contains everything else. Go there now:
   % cd src

Step 2. Run the configuration script.

Execute the command

   % ./configure [ variable=value ]...
This configure script generates the file "makefile" and the file "../include/NTL/config.h", based upon the values assigned to the variables on the command line.

Here are the most important variables, and their default values.

CXX=g++              # The C++ compiler
CXXFLAGS=-g -O2      # C++ complilation flags

DEF_PREFIX=/usr/local # Default software directory
PREFIX=$(DEF_PREFIX) # Directory in which to install NTL library components
SHARED=off           # Generate a shared library (as well as static)

NTL_THREADS=off      # compile in thread-safe mode
NTL_EXCEPTIONS=off   # compile with exceptions enabled

NTL_GMP_LIP=off      # Switch to enable the use of GMP as primary 
                     #   long integer package

GMP_PREFIX=$(DEF_PREFIX) # Directory in which GMP components are installed

NTL_PCLMUL=off       # switch to enable PCLMUL instruction for
                     #   faster arithmetic in GF(2)[X]

NTL_GF2X_LIB=off     # Switch to enable the use of the gf2x package
                     #   for faster arithmetic GF(2)[X]

GF2X_PREFIX=$(DEF_PREFIX) # Directory in which gf2x components are installed


There are a number of more esoteric configuration variables that can be set. See config.txt for a complete description.

Note that all of these configuration options can also be set by editing the two files makefile and ../include/NTL/config.h by hand. These files are fairly simple and well documented, and so this is not too hard to do.

Note that the file "../include/NTL/def_config.h" contains a backup copy of the original config.h file, and that the file "def_makefile" contains a backup copy of the original makefile file.

This command is intended only as a convenience and -- more importantly -- to allow the configuration process to be script driven. This script does not perform any "magic", like finding out what the local C compiler is called, etc. If the defaults are not correct for your platform, you have to set an appropriate variable.

Step 3. Execute make.

Just type:

   % make

The build process after this point is fully automatic. But here is a description of what happens.

  1. The makefile builds the file "../include/NTL/mach_desc.h", which defines some machine characteristics such as word size and machine precision. This is done by compiling and running a C program called MakeDesc that figures out these characteristics on its own, and prints some diagnostics to the terminal.

  2. A script is run that "automagically" determines the best way to write a timing function on your platform. It tries different routines in the files GetTime1.c, GetTime2.c, etc., and when it finds a good one, it copies the file into GetTime.c. A similar script is run to "automagically" determine if there is something like a getpid function available on your platform.

  3. The file "../include/NTL/gmp_aux.h" is generated for use with GMP. If not using GMP, this files are still created, but it is empty.

  4. The configuration wizard script is run. This script works in a sub-directory, compiling several programs, and performing a number of timing experiments, in order to determine the optimal setting for a number of flags in the file ../include/NTL/config.h. When the script finishes (it may take several minutes), you will be told what the wizard thinks are the best settings, and your config.h file will be automatically updated. Note that any flags you set in Step 2 will be in effect while the wizard runs, and will be retained in the updated config.h file, with the exception of the flags
    which are set by the wizard. Also note that if you do not want the wizard to run, you should pass WIZARD=off to the configure script; however, this is not recommended.

  5. The makefile will compile all the source files, and then creates the library "ntl.a" in the current directory.

Note that for finer control you can optionally break up this process into the five component steps:

   % make setup1
   % make setup2
   % make setup3
   % make setup4
   % make ntl.a

After NTL is built.

Executing make check runs a series of timing and test programs. It is a good idea to run this to see if everything really went well.

Executing make install copies a number of files to a directory <prefix> that you specify by passing PREFIX=<prefix> as an argument to configure at configuration time, or as an argument to make install at installation time. The default is /usr/local, so either you need root permissions, or you choose a <prefix> for which you have write permission. The files ../include/NTL/* are copied into <prefix>/include/NTL. The file ntl.a is copied to <prefix>/lib/libntl.a. The files ../doc/* are copied into <prefix>/share/doc/NTL.

You can also "fine tune" the installation procedure further. See the configure documentation for details.

Executing make uninstall undoes make install.

Executing make clobber essentially undoes make. Make sure you do this if you re-build NTL for a different architecture!

Executing make clean will remove object files, but not ntl.a. To rebuild after executing make clean, execute make ntl.a.

Assuming you have installed NTL as above, to compile a program foo.c that uses NTL, execute

   g++  -I<prefix>/include foo.c -o foo  -L<prefix>/lib -lntl  -lm
This compiles foo.c as a C++ program and creates the binary foo.

If you built NTL using GMP, execute:

   g++  -I<prefix>/include foo.c -o foo  -L<prefix>/lib -lntl  -L<gmp_prefix>/lib -lgmp  -lm

Of course, if <prefix> and <gmp_prefix> are the same, you do not need to duplicate the -L flags, and if either are standard directories, like /usr/local, you can leave out the corresponding -I and -L flags altogether.

Similarly, if you built NTL using gf2x, you should include flags

   -L<gf2x_prefix>/lib -lgf2x
on the command line.

This works even if you are not working in the directory in which you built NTL. If you are working in that directory, you can just execute

   make foo

Building a Shared Library

By default, the above installation procedure builds a static library only. Static libraries are nice because the procedures for building and using them are nearly identical across various flavors of Unix. However, static libraries have their drawbacks, and sometimes it is desirable to build a shared library. This can be done (in theory) by simply passing SHARED=on to NTL's configure.

If you set SHARED=on, then behind the scenes, the procedure used by the makefile changes a bit. In particular, the magical GNU program libtool is used to deal with all idiosyncracies of shared libraries. You may need to set the configuration variable LIBTOOL, to point to another version of libtool. For example, on Mac OSX, the built-in command called libtool is not actually the GNU libtool program; in this case, you will want to set LIBTOOL=glibtool. On other systems, it may be necssary to download and install a fresh copy of the libtool program (which can be obtained from here). Note that if SHARED=on, then in addition to using the libtool program, the makefile relies on features specific to GNU make.

Note that if you want to build NTL as a shared library, then if you use them, GMP and gf2x must also be built and installed as shared libraries. Also note that to use a shared library version of NTL, you may have to do something special, like set a special shell variable: the output generated by the libtool program during make install should give specific instructions. In addition, if NTL is built as a shared library, then you typically do not have to include -lgmp (if using GMP), or -lgf2x (if using gf2x), or corresponding -L flags, or -lm on the command line when compiling programs that use NTL.

32-bit and 64-bit ABIs

An ABI (Application Binary Interface) defines the sizes of various C data types. Typically, with a 32-bit ABI, int's and long's are 32 bits, while on a 64-bit ABI, int's are 32 bits and long's are 64 bits. Some platforms support both 64-bit and 32-bit ABI's; typically in such settings, the 64-bit ABI will yield much better performance, while the 32-bit ABI is available for backward compatibility. In addition, the 64-bit ABI may not be the default: if you are using gcc, you need to pass the -m64 flag to the compiler to get the 64-bit ABI.

When compiling NTL, you may want to try running configure with CFLAGS="-O2 -m64" to force a 64-bit ABI -- this may yield a very marked performance improvement.

If you are using NTL with either the GMP or gf2x libraries, then these must be built with the same ABI as NTL. The installation script for GMP will typically select the 64-bit ABI automatically if it is available. The installation script for gf2x may need some hints.

When compiling programs that use NTL, you must also ensure that the program is compiled with the same ABI as NTL. Again, if you want a 64-bit ABI, then just pass the flag -m64 to the compiler.

[Previous] [Up] [Next]