1 | <html> |
---|
2 | <head> |
---|
3 | <title> |
---|
4 | A Tour of NTL: Obtaining and Installing NTL for UNIX </title> |
---|
5 | </head> |
---|
6 | |
---|
7 | <body bgcolor="#fff9e6"> |
---|
8 | <center> |
---|
9 | <a href="tour-stdcxx.html"><img src="arrow1.gif" alt="[Previous]" align=bottom></a> |
---|
10 | <a href="tour.html"><img src="arrow2.gif" alt="[Up]" align=bottom></a> |
---|
11 | <a href="tour-win.html"> <img src="arrow3.gif" alt="[Next]" align=bottom></a> |
---|
12 | </center> |
---|
13 | |
---|
14 | <h1> |
---|
15 | <p align=center> |
---|
16 | A Tour of NTL: Obtaining and Installing NTL for UNIX |
---|
17 | </p> |
---|
18 | </h1> |
---|
19 | |
---|
20 | <p> <hr> <p> |
---|
21 | |
---|
22 | This procedure should work on most Unix or Unix-like platorms |
---|
23 | (including MAC OSX, and Windows with Cygwin tools). |
---|
24 | |
---|
25 | <p> |
---|
26 | |
---|
27 | |
---|
28 | To obtain the source code and documentation for NTL, |
---|
29 | <a href="http://www.shoup.net/ntl/download.html"> |
---|
30 | download <tt>ntl-xxx.tar.gz</tt></a>, |
---|
31 | placing it a directory, and then, working in this directory, |
---|
32 | do the following. |
---|
33 | Here, "<tt>xxx</tt>" denotes the current version number. |
---|
34 | |
---|
35 | |
---|
36 | |
---|
37 | <p> |
---|
38 | <pre> |
---|
39 | % gunzip ntl-xxx.tar.gz |
---|
40 | % tar xf ntl-xxx.tar |
---|
41 | % cd ntl-xxx/src |
---|
42 | % ./configure PREFIX=$HOME/sw |
---|
43 | % make |
---|
44 | % make check |
---|
45 | % make install |
---|
46 | </pre> |
---|
47 | |
---|
48 | This will build, test, and install NTL in <tt>$HOME/sw</tt>. |
---|
49 | Of course, change <tt>$HOME/sw</tt> to whatever you want (the default is |
---|
50 | <tt>/usr/local</tt>). |
---|
51 | You will find the NTL header files in <tt>$HOME/sw/include/NTL</tt> |
---|
52 | and the compiled binary |
---|
53 | in <tt>$HOME/sw/lib/libntl.a</tt>. |
---|
54 | <p> |
---|
55 | If you really are interested in high-performace, you will |
---|
56 | <i>definitely</i> want to build NTL |
---|
57 | using GMP (the GNU Multi-Precision package). |
---|
58 | If GMP has already been installed in a standard |
---|
59 | system library, like <tt>/usr/local</tt>, then invoke <tt>configure</tt> |
---|
60 | above as |
---|
61 | <pre> |
---|
62 | % ./configure PREFIX=$HOME/sw NTL_GMP_LIP=on |
---|
63 | </pre> |
---|
64 | and if GMP is installed somewhere else, say <tt>$HOME/sw</tt>, then |
---|
65 | <pre> |
---|
66 | % ./configure PREFIX=$HOME/sw NTL_GMP_LIP=on GMP_PREFIX=$HOME/sw |
---|
67 | </pre> |
---|
68 | does the job. |
---|
69 | <a href="tour-gmp.html">This page</a> provides more |
---|
70 | details. |
---|
71 | |
---|
72 | |
---|
73 | <p> |
---|
74 | Now suppose you want to compile a program that uses NTL. |
---|
75 | Suppose you are working in some directory and <tt>foo.c</tt> |
---|
76 | is your program. |
---|
77 | Assume that you have installed NTL in <tt>$HOME/sw</tt> as above. |
---|
78 | The following should work: |
---|
79 | <pre> |
---|
80 | % g++ -I$HOME/sw/include -L$HOME/sw/lib foo.c -o foo -lntl -lm |
---|
81 | </pre> |
---|
82 | If you are using GMP, then: |
---|
83 | <pre> |
---|
84 | % g++ -I$HOME/sw/include -L$HOME/sw/lib foo.c -o foo -lntl -lgmp -lm |
---|
85 | </pre> |
---|
86 | |
---|
87 | <p> |
---|
88 | <h2> |
---|
89 | More Details |
---|
90 | </h2> |
---|
91 | <p> |
---|
92 | What follows is a more detailed description of the installation process. |
---|
93 | |
---|
94 | |
---|
95 | |
---|
96 | |
---|
97 | <p> |
---|
98 | <b>Step 1.</b> |
---|
99 | Extract the source files by executing: |
---|
100 | <pre> |
---|
101 | % gunzip ntl-xxx.tar.gz |
---|
102 | % tar xvf ntl-xxx.tar |
---|
103 | </pre> |
---|
104 | |
---|
105 | <p> |
---|
106 | Note that this will unpack everything into a sub-directory <tt>ntl-xxx</tt>, |
---|
107 | creating this directory if necessary. |
---|
108 | Next: |
---|
109 | <pre> |
---|
110 | % cd ntl-xxx |
---|
111 | % ls |
---|
112 | </pre> |
---|
113 | You should see a file "<tt>README</tt>", and directories |
---|
114 | "<tt>include</tt>", "<tt>doc</tt>", and "<tt>src</tt>". |
---|
115 | The directory "<tt>doc</tt>" contains all the documentation. |
---|
116 | The file "<tt>doc/tour.html</tt>" contains a copy of the on-line documentation. |
---|
117 | The directory "<tt>include</tt>" |
---|
118 | contains all the header files within a subdirectory |
---|
119 | "<tt>include/NTL</tt>". |
---|
120 | The directory "<tt>src</tt>" contains everything else. |
---|
121 | Go there now: |
---|
122 | <pre> |
---|
123 | % cd src |
---|
124 | </pre> |
---|
125 | |
---|
126 | <p> |
---|
127 | <b>Step 2.</b> |
---|
128 | Run the configuration script. |
---|
129 | |
---|
130 | <p> |
---|
131 | Execute the command |
---|
132 | <pre> |
---|
133 | % ./configure [ variable=value ]... |
---|
134 | </pre> |
---|
135 | |
---|
136 | This configure script generates the file "<tt>makefile</tt>" and the file |
---|
137 | "<tt>../include/NTL/config.h</tt>", based upon the values assigned to the |
---|
138 | variables on the command line. |
---|
139 | |
---|
140 | |
---|
141 | <p> |
---|
142 | |
---|
143 | Here are the most important variables, and their default values. |
---|
144 | |
---|
145 | <p> |
---|
146 | <pre> |
---|
147 | CC=gcc # The C compiler |
---|
148 | CXX=g++ # The C++ compiler |
---|
149 | CFLAGS=-O2 # C complilation flags |
---|
150 | CXXFLAGS=$(CFLAGS) # C++ compilation flags (by default, same as CFLAGS) |
---|
151 | |
---|
152 | PREFIX=/usr/local # Directory in which to install NTL library components |
---|
153 | |
---|
154 | NTL_STD_CXX=on # ISO Mode switch |
---|
155 | |
---|
156 | NTL_GMP_LIP=off # Switch 'on' to enable the use of GMP as the primary |
---|
157 | # long integer package |
---|
158 | |
---|
159 | GMP_PREFIX=none # Directory in which GMP components have been installed |
---|
160 | </pre> |
---|
161 | |
---|
162 | <p> |
---|
163 | <i>Examples.</i> |
---|
164 | <p> |
---|
165 | |
---|
166 | <ul> |
---|
167 | <li> |
---|
168 | If you are happy with all the default values, run: |
---|
169 | <pre> |
---|
170 | % ./configure |
---|
171 | </pre> |
---|
172 | Actually, the initially installed <tt>makefile</tt> and <tt>config.h</tt> files |
---|
173 | already reflect the default values, and you do not have to even run |
---|
174 | the configure script. |
---|
175 | |
---|
176 | <p> |
---|
177 | <li> |
---|
178 | If your C/C++ compilers are called cc/CC, run: |
---|
179 | <pre> |
---|
180 | % ./configure CC=cc CXX=CC |
---|
181 | </pre> |
---|
182 | |
---|
183 | <p> |
---|
184 | <li> |
---|
185 | If you want to use, say, the options <tt>-g</tt> and <tt>-O</tt> for |
---|
186 | compiling <tt>C</tt> and <tt>C++</tt>, run: |
---|
187 | <pre> |
---|
188 | % ./configure "CFLAGS=-g -O" |
---|
189 | </pre> |
---|
190 | Note the use of quotes to keep the argument in one piece. |
---|
191 | |
---|
192 | <p> |
---|
193 | <li> |
---|
194 | If <a href="tour-gmp.html">GMP (the GNU Multi-Precision package)</a> |
---|
195 | is installed in a standard system directory, and you want to use it |
---|
196 | to obtain better performance for long integer arithemtic, run: |
---|
197 | <pre> |
---|
198 | % ./configure NTL_GMP_LIP=on |
---|
199 | </pre> |
---|
200 | If GMP was installed in |
---|
201 | <tt>$HOME/sw</tt>, |
---|
202 | run: |
---|
203 | <pre> |
---|
204 | % ./configure NTL_GMP_LIP=on GMP_PREFIX=$HOME/sw |
---|
205 | </pre> |
---|
206 | Go <a href="tour-gmp.html">here</a> for complete details. |
---|
207 | |
---|
208 | <p> |
---|
209 | <li> |
---|
210 | If you want to use |
---|
211 | <a href="tour-stdcxx.html">traditional rather than ISO mode</a>, run: |
---|
212 | <pre> |
---|
213 | % ./configure NTL_STD_CXX=off |
---|
214 | </pre> |
---|
215 | |
---|
216 | <p> |
---|
217 | <li> |
---|
218 | If you want to install NTL in the directory <tt>$HOME/sw</tt>, |
---|
219 | run: |
---|
220 | <pre> |
---|
221 | % ./configure PREFIX=$HOME/sw |
---|
222 | </pre> |
---|
223 | </ul> |
---|
224 | |
---|
225 | <p> |
---|
226 | There are a number of more esoteric configuration variables that can be set. |
---|
227 | See <a href="config.txt"><tt>config.txt</tt></a> for a complete |
---|
228 | description. |
---|
229 | |
---|
230 | <p> |
---|
231 | Note that all of these configuration options can also be set |
---|
232 | by editing the two files <tt>makefile</tt> |
---|
233 | and <tt>../include/NTL/def_config.h</tt> by hand. |
---|
234 | These files are fairly simple and well documented, and so this is not |
---|
235 | too hard to do. |
---|
236 | |
---|
237 | <p> |
---|
238 | Note that the file "<tt>../include/NTL/def_config.h</tt>" |
---|
239 | contains a backup copy of the original <tt>config.h</tt> file, |
---|
240 | and that the file "<tt>def_makefile</tt>" |
---|
241 | contains a backup copy of the original <tt>makefile</tt> file. |
---|
242 | |
---|
243 | <p> |
---|
244 | This command is intended only as a convenience |
---|
245 | and -- more importantly -- to allow the configuration process |
---|
246 | to be script driven. |
---|
247 | This script does not perform any "magic", like finding out what |
---|
248 | the local C compiler is called, etc. |
---|
249 | If the defaults are not |
---|
250 | correct for your platform, you have to set an appropriate variable. |
---|
251 | |
---|
252 | |
---|
253 | |
---|
254 | <p> |
---|
255 | <b>Step 3.</b> |
---|
256 | Execute <tt>make</tt>. |
---|
257 | |
---|
258 | <p> |
---|
259 | Just type: |
---|
260 | <pre> |
---|
261 | % make |
---|
262 | </pre> |
---|
263 | |
---|
264 | <p> |
---|
265 | The build process after this point is fully automatic. |
---|
266 | But here is a description of what happens. |
---|
267 | |
---|
268 | <p> |
---|
269 | |
---|
270 | <ol> |
---|
271 | <li> |
---|
272 | The makefile |
---|
273 | builds the file "<tt>../include/NTL/mach_desc.h</tt>", which defines some machine characteristics |
---|
274 | such as word size and machine precision. |
---|
275 | This is done by compiling and running a <tt>C</tt> program |
---|
276 | called <tt>MakeDesc</tt> |
---|
277 | that figures out these characteristics on its |
---|
278 | own, and prints some diagnostics to the terminal. |
---|
279 | |
---|
280 | <p> |
---|
281 | <li> |
---|
282 | A script is run that "automagically" |
---|
283 | determines the best way to write a timing function |
---|
284 | on your platform. |
---|
285 | It tries different routines in the files <tt>GetTime1.c</tt>, |
---|
286 | <tt>GetTime2.c</tt>, etc., and when it finds a good one, |
---|
287 | it copies the file into <tt>GetTime.c</tt>. |
---|
288 | |
---|
289 | <p> |
---|
290 | <li> |
---|
291 | The files "<tt>lip_gmp_aux_impl.h</tt>" and "<tt>../include/NTL/gmp_aux.h</tt>" |
---|
292 | are generated for use with GMP. |
---|
293 | If not using GMP, these files are still created, but they are empty. |
---|
294 | |
---|
295 | |
---|
296 | <p> |
---|
297 | <li> |
---|
298 | The configuration wizard script is run. |
---|
299 | This script works in a sub-directory, |
---|
300 | compiling several programs, |
---|
301 | and performing a number of timing experiments, |
---|
302 | in order to determine the optimal setting for a number of flags |
---|
303 | in the file <tt>../include/NTL/config.h</tt>. |
---|
304 | When the script finishes (it may take several minutes), |
---|
305 | you will be told what the wizard thinks are the best settings, |
---|
306 | and your <tt>config.h</tt> file will be automatically updated. |
---|
307 | Note that any flags you set in Step 2 |
---|
308 | will be in |
---|
309 | effect while the wizard runs, and will be retained in the updated |
---|
310 | <tt>config.h</tt> file, with the exception of the flags |
---|
311 | <pre> |
---|
312 | NTL_LONG_LONG NTL_AVOID_FLOAT NTL_TBL_REM NTL_AVOID_BRANCHING |
---|
313 | NTL_SPMM_UL NTL_SPMM_ULL NTL_SPMM_ASM NTL_GF2X_NOINLINE NTL_GF2X_ALTCODE |
---|
314 | </pre> |
---|
315 | which are set by the wizard. |
---|
316 | Also note that if you <i>do not</i> want the wizard to run, |
---|
317 | you should pass <tt>WIZARD=off</tt> to the configure script; |
---|
318 | however, this is not recommended. |
---|
319 | |
---|
320 | <p> |
---|
321 | <li> |
---|
322 | The makefile will compile all the source files, |
---|
323 | and then creates the library "<tt>ntl.a</tt>" in the current directory. |
---|
324 | </ol> |
---|
325 | |
---|
326 | <p> |
---|
327 | Note that for finer control you can optionally break up this process |
---|
328 | into the five |
---|
329 | component steps: |
---|
330 | <pre> |
---|
331 | % make setup1 |
---|
332 | % make setup2 |
---|
333 | % make setup3 |
---|
334 | % make setup4 |
---|
335 | % make ntl.a |
---|
336 | </pre> |
---|
337 | |
---|
338 | |
---|
339 | <p> |
---|
340 | |
---|
341 | <p> |
---|
342 | <b>After NTL is built.</b> |
---|
343 | |
---|
344 | <p> |
---|
345 | Executing <tt>make check</tt> runs a series of timing and test programs. |
---|
346 | It is a good idea to run this to see if everything really |
---|
347 | went well. |
---|
348 | |
---|
349 | <p> |
---|
350 | Executing <tt>make install</tt> |
---|
351 | copies a number of files to a directory <tt><prefix></tt> that you |
---|
352 | specify by passing <tt>PREFIX=<prefix></tt> |
---|
353 | as an argument to <tt>configure</tt> at configuration time, |
---|
354 | or as an argument to <tt>make install</tt> at installation time. |
---|
355 | The default is <tt>/usr/local</tt>, so either you need root |
---|
356 | permissions, or you choose a <tt><prefix></tt> for which |
---|
357 | you have write permission. |
---|
358 | The files <tt>../include/NTL/*</tt> are copied into |
---|
359 | <tt><prefix>/include/NTL</tt>. |
---|
360 | The file <tt>ntl.a</tt> is copied to <tt><prefix>/lib/libntl.a</tt>. |
---|
361 | The files <tt>../doc/*</tt> are copied into |
---|
362 | <tt><prefix>/doc/NTL</tt>. |
---|
363 | |
---|
364 | <p> |
---|
365 | You can also "fine tune" the installation procedure further. |
---|
366 | See the <a href="config.txt">configure documentation</a> for details. |
---|
367 | |
---|
368 | <p> |
---|
369 | Executing <tt>make uninstall</tt> undoes <tt>make install</tt>. |
---|
370 | |
---|
371 | |
---|
372 | <p> |
---|
373 | Executing <tt>make clobber</tt> essentially |
---|
374 | undoes <tt>make</tt>. |
---|
375 | <i>Make sure you do this if you re-build NTL for a different architecture!</i> |
---|
376 | |
---|
377 | <p> |
---|
378 | Executing <tt>make clean</tt> will remove object files, but not |
---|
379 | <tt>ntl.a</tt>. |
---|
380 | To rebuild after executing <tt>make clean</tt>, execute <tt>make ntl.a</tt>. |
---|
381 | |
---|
382 | |
---|
383 | <p> |
---|
384 | Assuming you have installed NTL as above, |
---|
385 | to compile a program <tt>foo.c</tt> that uses NTL, |
---|
386 | execute |
---|
387 | <pre> |
---|
388 | g++ -I<prefix>/include -L<prefix>/lib foo.c -o foo -lntl -lm |
---|
389 | </pre> |
---|
390 | This compiles <tt>foo.c</tt> as a <tt>C++</tt> program |
---|
391 | and creates the binary <tt>foo</tt>. |
---|
392 | <p> |
---|
393 | If you built NTL using <a href="tour-gmp.html">GMP</a>, execute: |
---|
394 | <pre> |
---|
395 | g++ -I<prefix>/include -L<prefix>/lib -L<gmp_prefix>/lib foo.c -lntl -lgmp -lm |
---|
396 | </pre> |
---|
397 | <p> |
---|
398 | Of course, if <tt><prefix></tt> and <tt><gmp_prefix></tt> |
---|
399 | are the same, you do not need to duplicate the <tt>-L</tt> |
---|
400 | flags, and if either are standard directories, like <tt>/usr/local</tt>, |
---|
401 | you can leave out the corresponding <tt>-I</tt> and <tt>-L</tt> |
---|
402 | flags altogether. |
---|
403 | <p> |
---|
404 | This works even if you are not working in the directory |
---|
405 | in which you built NTL. |
---|
406 | If you <i>are</i> working in that directory, you can just execute |
---|
407 | <pre> |
---|
408 | make foo |
---|
409 | </pre> |
---|
410 | |
---|
411 | |
---|
412 | <p> <p> |
---|
413 | <p> <p> |
---|
414 | |
---|
415 | <center> |
---|
416 | <a href="tour-stdcxx.html"><img src="arrow1.gif" alt="[Previous]" align=bottom></a> |
---|
417 | <a href="tour.html"><img src="arrow2.gif" alt="[Up]" align=bottom></a> |
---|
418 | <a href="tour-win.html"> <img src="arrow3.gif" alt="[Next]" align=bottom></a> |
---|
419 | </center> |
---|
420 | |
---|
421 | </body> |
---|
422 | </html> |
---|