[bfa10a]: doc / manual / jags_installation_manual.tex  Maximize  Restore  History

Download this file

656 lines (558 with data), 26.7 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
\documentclass[11pt, a4paper, titlepage]{article}
\usepackage{amsmath}
\usepackage{a4wide}
\usepackage{url}
\usepackage{multirow}
\usepackage{amsfonts}
\newcommand{\release}{2.0.0}
\newcommand{\JAGS}{\textsf{JAGS}}
\newcommand{\BUGS}{\textsf{BUGS}}
\newcommand{\WinBUGS}{\textsf{WinBUGS}}
\newcommand{\R}{\textsf{R}}
\newcommand{\CODA}{\textsf{coda}}
\begin{document}
\title{JAGS Version \release\ installation manual}
\author{Martyn Plummer \and Bill Northcott}
\maketitle
\JAGS\ is distributed in binary format for Microsoft Windows, Mac OS
X, and most Linux distributions. The following instructions are for
those who wish to build \JAGS\ from source. The manual is divided
into three sections with instructions for Linux/Unix, Mac OS X, and Windows.
\section{Linux and UNIX}
\JAGS\ follows the usual GNU convention of
\begin{verbatim}
./configure
make
make install
\end{verbatim}
which is described in more detail in the file \texttt{INSTALL} in
the top-level source directory. On some UNIX platforms, you may
be required to use GNU make (gmake) instead of the native make
command. On systems with multiple processors, you may use the option
\verb+-j+ to speed up compilation, {\em e.g.} for a quad-core PC you
may use:
\begin{verbatim}
make -j4
\end{verbatim}
\subsection{Configure options}
At configure time you also have the option of defining options such
as:
\begin{itemize}
\item The names of the C, C++, and Fortran compilers. Although
\JAGS\ contains no Fortran code, you are required to define a
Fortran compiler so that \JAGS\ modules can be linked against
libraries written in Fortran (such as BLAS and LAPACK)
\item Optimization flags for the C and C++ compilers. \JAGS\ is
optimized by default if the GNU compiler (gcc) is used. Otherwise
you must explicitly supply optimization flags.
\item Installation directories. \JAGS\ conforms to the GNU standards
for where files are installed. You can control the installation
directories in more detail using the flags that are listed when
you type \verb+./configure --help+.
\end{itemize}
\subsubsection{Configuration for a 64-bit build}
By default, JAGS will install all libraries into
\verb+/usr/local/lib+. If you are building a 64-bit version of \JAGS,
this may not be appropriate for your system. On Fedora and other
RPM-based distributions, for example, 64-bit libraries should be
installed in \verb+lib64+, and on Solaris, 64-bit libraries are in a
subdirectory of \verb+lib+ ({\em e.g.} \verb+lib/amd64+ if you are
using a x86-64 processor), whereas on Debian, and other Linux
distributions that conform to the FHS, the correct installation
directory is \verb+lib+.
To ensure that \JAGS\ libraries are installed in the correct
directory, you should supply the \verb+--libidr+ argument to the
configure script, {\em e.g.}:
\begin{verbatim}
./configure --libdir=/usr/local/lib64
\end{verbatim}
It is important to get the installation directory right when using the
\texttt{rjags} interface between R and \JAGS, otherwise the
\texttt{rjags} package will not be able to find the \JAGS\ library.
\subsubsection{Configuration for a private installation}
If you do not have administrative privileges, you may wish to install
\JAGS\ in your home directory. This can be done with the following
configuration options
\begin{verbatim}
export JAGS_HOME=$HOME/jags #or wherever you want it
./configure --bindir=$JAGS_HOME/bin --libdir=$JAGS_HOME/lib \
--libexecdir=$JAGS_HOME/bin --includedir=$JAGS_HOME/include
\end{verbatim}
You then need to modify your PATH environment variable to include
\verb+$JAGS_HOME/bin+. You may also need to set \verb+LD_LIBRARY_PATH+
to include \verb+$JAGS_HOME/lib+ (On Linux this is not necessary as
the location of libjags and libjrmath is hard-coded into the
\JAGS\ binary).
\subsection{BLAS and LAPACK}
\label{section:blas:lapack}
BLAS (Basic Linear Algebra System) and LAPACK (Linear Algebra Pack)
are two libraries of routines for linear algebra. They are used by the
multivariate functions and distributions in the \texttt{bugs} module.
Most unix-like operating system vendors supply shared libraries that
provide the BLAS and LAPACK functions, although the libraries may not
literally be called ``blas'' and ``lapack''. During configuration, a
default list of these libraries will be checked. If \texttt{configure}
cannot find a suitable library, it will stop with an error message.
You may use alternative BLAS and LAPACK libraries using the configure
options \texttt{--with-blas} and \texttt{--with-lapack}
\begin{verbatim}
./configure --with-blas="-lmyblas" --with-lapack="-lmylapack"
\end{verbatim}
If the BLAS and LAPACK libraries are in a directory that is not on the
default linker path, you must set the \verb+LDFLAGS+ environment variable
to point to this directory at configure time:
\begin{verbatim}
LDFLAGS="-L/path/to/my/libs" ./configure ...
\end{verbatim}
If your BLAS and LAPACK libraries depend on other libraries that are
not on the linker path, you must supply these dependency libraries as
additional arguments to \texttt{--with-blas} and
\texttt{--with-lapack}
At runtime, if you have linked \JAGS\ against BLAS or LAPACK in
a non-standard location, you must supply this location with the
environment variable \verb+LD_LIBRARY_PATH+, {\em e.g.}
\begin{verbatim}
LD_LIBRARY_PATH="/path/to/my/libs:${LD_LIBRARY_PATH}"
\end{verbatim} %$
Alternatively, you may hard-code the paths to the blas and lapack
libraries at compile time. This is compiler and platform-specific,
but is typically achieved with
\begin{verbatim}
LDFLAGS="-L/path/to/my/libs -R/path/to/my/libs
\end{verbatim}
\subsection{GNU/Linux}
\label{section:gnulinux}
GNU/Linux is the development platform for \JAGS, and a variety of
different build options have been explored, including the use of
third-party compilers and linear algebra libraries.
\subsubsection{Fortran compiler}
The GNU FORTRAN compiler changed between gcc 3.x and gcc 4.x from
\verb+g77+ to \verb+gfortran+. Code produced by the two compilers is
binary incompatible. If your BLAS and LAPACK libraries are linked
against \verb+libgfortran+, then they were built with \verb+gfortran+
and you must also use this to compile \JAGS.
Most recent GNU/Linux distributions have moved completely to gcc 4.x.
However, some older systems may have both compilers installed.
Unfortunately, if \verb+g77+ is on your path then the configure script
will find it first, and will attempt to use it to build \JAGS. This
results in a failure to recognize the installed BLAS and LAPACK
libraries. In this event, set the \verb+F77+ variable at configure time.
\begin{verbatim}
F77=gfortran ./configure
\end{verbatim}
\subsubsection{BLAS and LAPACK}
The {\bf BLAS} and {\bf LAPACK} libraries from Netlib
(\url{http://www.netlib.org}) should be provided as part of your Linux
distribution. If your Linux distribution splits packages into ``user''
and ``developer'' versions, then you must install the developer
package ({\em e.g.} \texttt{blas-devel} and \texttt{lapack-devel}).
{\bf Suse Linux Enterprise Server (SLES)} does not include BLAS and
LAPACK in the main distribution. They are included in the SLES SDK, on
a set of CD/DVD images which can be downloaded from the Novell web
site. See \url{http://developer.novell.com/wiki/index.php/SLES_SDK}
for more information.
It is quite common for the Netlib implementations of BLAS and LAPACK
to break when they are compiled with the latest GNU compilers. Linux
distributions that use ``bleeding edge'' development tools -- such as
{\bf Fedora} -- may ship with a broken version of BLAS and
LAPACK. Normally, this problem is quickly identified and
fixed. However, you need to take care to use the online updates of the
BLAS and LAPACK packages from your Linux Distributor, and not rely on
the version that came on the installation disk.
\subsubsection{ATLAS}
On Fedora Linux, pre-compiled atlas libraries are available via the
\texttt{atlas} and \texttt{atlas-devel} RPMs. These RPMs install the
atlas libraries in the non-standard directory \texttt{/usr/lib/atlas}
(or \texttt{/usr/lib64/atlas} for 64-bit builds) to avoid conflicts
with the standard \texttt{blas} and \texttt{lapack} RPMs. To use the
atlas libraries, you must supply their location using the
\verb+LDFLAGS+ variable (see section \ref{section:blas:lapack})
\begin{verbatim}
./configure LDFLAGS="-L/usr/lib/atlas"
\end{verbatim}
Runtime linking to the correct libraries is ensured by the automatic
addition of \texttt{/usr/lib/atlas} to the linker path (see the file
\texttt{/etc/ld.so.conf}), so you do not need to set the
environment variable \verb+LD_LIBRARY_PATH+ at run time.
\subsubsection{AMD Core Math Library}
\label{section:acml:linux}
The AMD Core Math Library (acml) provides optimized BLAS and LAPACK
routines for AMD processors. To link \JAGS\ with \texttt{acml}, you
must supply the \texttt{acml} library, {\em and its dependencies}, as
arguments to \texttt{--with-blas}. It is not necessary to set the
\texttt{--with-lapack} argument as \texttt{acml} provides both sets of
functions. See also section~\ref{section:blas:lapack} for run-time
instructions.
For example, to link to the 64-bit acml using gcc 4.0+:
\begin{verbatim}
LDFLAGS="-L/opt/acml4.3.0/gfortran64/lib" \
./configure --with-blas="-lacml -lacml_mv -lgfortran"
\end{verbatim}
The library \verb+acmv_mv+ library is a vectorized math library that
exists only for the 64-bit version and is omitted when linking against
32-bit acml.
On multi-core systems, you may wish to use the threaded acml library.
To do this, link to \verb+acml_mp+ and add the compiler flag
\verb+-fopenmp+:
\begin{verbatim}
LDFLAGS="-L/opt/acml4.3.0/gfortran64_mp/lib" \
CXXFLAGS="-O2 -g -fopenmp" ./configure --with-blas="-lacml_mp -lacml_mv -lgfortran"
\end{verbatim}
The number of threads used by multi-threaded acml may be controlled
with the environment variable \verb+OMP_NUM_THREADS+.
For older Linux systems, the last version that supports gcc 3.4 is
\texttt{acml} 3.6.0. When using gcc 3.4, link against \texttt{libg2c}.
\begin{verbatim}
LDFLAGS="-L/opt/acml3.6.0/gnu64/lib" \
./configure --with-blas="-lacml -lacml_mv -lg2c"
\end{verbatim}
\subsubsection{Intel Math Kernel Library}
The Intel Math Kernel library (MKL) provides optimized BLAS and LAPACK
routines for Intel processors. The instructions below are for MKL
version 10.0 and above which use a ``pure layered'' model for linking.
The layered model gives the user fine-grained control over four
different library layers: interface, threading, computation, and
run-time library support. Some examples of linking to MKL using this
layered model are given below. These examples are for GCC compilers on
\verb+x86_64+. The choice of interface layer is important on
\verb+x86_64+ since the Intel Fortran compiler returns complex values
differently from the GNU Fortran compiler. You must therefore use the
interface layer that matches your compiler (\verb+mkl_intel*+ or
\verb+mkl_gf*+).
I have not been able to link \JAGS\ with MKL using GNU compilers, except
which building a static version. To build a static version of \JAGS,
use the configure option \verb+--disable-shared+. The \JAGS\ library and
modules will be linked into the main executable.
JAGS can be linked to a sequential version of MKL by
\begin{verbatim}
MKL_HOME=/opt/intel/mkl/10.0.3.020/
MKL_LIB_PATH=${MKL_HOME}/lib/em64t/
./configure --disable-shared \
--with-blas="-L${MKL_LIB_PATH} -lmkl_gf_lp64 -lmkl_sequential -lmkl_core"
\end{verbatim}
Threaded MKL may be used with:
\begin{verbatim}
./configure --disable-shared\
--with-blas="-L${MKL_LIB_PATH} -lmkl_gf_lp64 -lmkl_gnu_thread -lmkl_core -liomp5 -lpthread"
\end{verbatim}
The default number of threads will be chosen by the OpenMP software,
but can be controlled by setting \verb+OMP_NUM_THREADS+ or \verb+MKL_NUM_THREADS+.
\subsubsection{Using Intel Compilers}
\JAGS\ has been successfully built with the Intel C, C++ and Fortran
compilers. The additional configure options required to use the Intel
compilers are:
\begin{verbatim}
source /opt/intel/Compiler/11.1/bin/ifortvars.sh
source /opt/intel/Compiler/11.1/bin/iccvars.sh
CC=icc CXX=icpc F77=ifort ./configure
\end{verbatim}
\subsection{OpenSolaris}
\JAGS\ has been successfully built and tested on the Intel x86
platform under OpenSolaris 2008.05 using the Sun Studio Express 5/08
compilers.
\begin{verbatim}
./configure CC=cc CXX=CC F77=f95 \
CFLAGS="-xO3 -xarch=sse2" \
FFLAGS="-xO3 -xarch=sse2" \
CXXFLAGS="-xO3 -xarch=sse2"
\end{verbatim}
The Sun Studio compiler is not optimized by default. Use the option
\verb+-xO3+ for optimization (NB This is the letter ``O'' not the
number ``0'') In order to use the optimization flag \verb+-xO3+ you
must specify the architecture with the \verb+-xarch+ flag. The options
above are for an Intel processor with SSE2 instructions. This must be
adapted to your own platform.
To compile a 64-bit version of JAGS, add the option \verb+-m64+ to
all the compiler flags.
Solaris provides two versions of the C++ standard library:
\texttt{libCstd}, which is the default, and \texttt{libstlport4},
which conforms more closely to the C++ standard. \JAGS\ may be linked
to the stlport4 library by adding the options
\verb+-library=stlport4 -lCrun+ to \verb+CXXFLAGS+.
The configure script automatically detects the Sun Performance library,
which implements the BLAS/LAPACK functions. Automatic detection may
not work on older versions of Sun Studio, which used a different syntax
for specifying this library. In this case, you may need to use the
configure option
\begin{verbatim}
--with-blas="-xlic_lib=sunperf -lsunmath"
\end{verbatim}
\subsubsection{Using acml}
AMD provides a version of their Core Math Library (acml) for
Solaris. To use this library instead of the Sun Performance library
add the following configure options (changing paths as appropriate):
\begin{verbatim}
--with-blas="-lacml -lacml_mv -lfsu" \
LDFLAGS="-L/opt/acml4.1.0/sun64/lib \
-R/opt/acml4.1.0/sun64/lib:/opt/SunStudioExpress/lib"
\end{verbatim}
The acml library is only available in 64-bit mode, so the option
\verb+-m64+ must also be added to all the compiler flags.
As with using acml on Linux (section \ref{section:acml:linux}), the
configure option \verb+--with-blas+ must include not only the acml
library, but also its dependencies. The \verb+LDFLAGS+ option \verb+-R+
hard-codes the paths to these libraries into the JAGS modules that
require them.
\subsection{IRIX}
\JAGS\ has not been tested on IRIX for some time. Version 1.0.0 was
successfully built using the MIPSpro 7.4 compiler on IRIX 6.5. The
following configure options were used:
\begin{verbatim}
./configure CC=cc CXX=CC F77=f77 \
CFLAGS="-O2 -g2 -OPT:IEEE_NaN_inf=ON" \
CXXFLAGS="-O2 -g2 -OPT:IEEE_NaN_inf=ON"
\end{verbatim}
and \JAGS\ was built with \verb+gmake+ (GNU make).
BLAS and LAPACK functions on IRIX are provided by the Scientific
Computing Software library (\verb+scs+). The presence of this library
is detected automatically by the configure script.
When using the MIPSpro compiler, optimization flags must be given
explicitly at configure time. If this is not done, then \JAGS\ will
not be optimized at all and will run slowly.
\clearpage
\section{Mac OS X}
If trying to build software on Mac OS X you really need to use Leopard
(10.5.x) or Snow Leopard (10.6.x). Unless otherwise stated these
instruction assume Snow Leopard (10.6.x). The open source support has
improved greatly in recent releases. You also need the latest version
of Apple's Xcode development tools. The current version is Xcode 3.2.x
(Leopard uses 3.1.x). Early versions have serious bugs which affect R
and \JAGS. Xcode is available as a free download from
\url{http://developer.apple.com}. You need to set up a free login to
ADC. The Apple developer tools do not include a Fortran
compiler. Without Fortran, you will not be able to build \JAGS.
For instructions for building on Tiger or for older versions of
\R\ see previous versions of this manual.
The GNU gfortran Fortran compiler is included in the \R\ binary
distribution available on CRAN. Install the \R\ binary and select all
the optional components in the `Customize' step of the installer.
These instructions assume R-2.7.x.
The default C/C++ compiler for Snow Leopard is gcc-4.2.x. Xcode 3.2
also includes gcc-4.2 and llvm-gcc4.2. The code has been successfully
built with these optional compilers but will only run on Leopard.
llvm is being actively developed by Apple and may produce better code.
MacOS X 10.2 and onwards include optimised versions of the BLAS and
LAPACK libraries. So no extra libraries are is needed for Snow
Leopard. Optimisation continues andApple are working on using GPUs
for this sort of math. Make sure your OS is up to date.
To ensure the \JAGS\ configure script can find the Fortran compiler
for a bash shell
\begin{verbatim}
export F77=/usr/local/bin/gfortran
\end{verbatim}
On 64 bit hardware, which means most recent Macs, there may be a
problem with the Fortran compiler. Apple's compilers default to 64 bit
builds on 64 bit hardware but the Fortran binaries available default to
32 bit builds. This means you need to add compile and link options.
For instance on 64 bit Intel Macs type
\begin{verbatim}
export CFLAGS='-arch x86_64'
export CXXFLAGS='-arch x86_64'
export FFLAGS='-arch x86_64'
export LDFLAGS='-arch x86_64'
\end{verbatim}
Some Fortran compilers (not the ones from CRAN) do not understand
the -arch option. For these you will need something like:
\begin{verbatim}
export CFLAGS='-arch x86_64'
export CXXFLAGS='-arch x86_64'
export FFLAGS='-m64'
export LDFLAGS='-arch x86_64'
\end{verbatim}
To build \JAGS\ unpack the source code and cd into the source
directory. Type the following:
\begin{verbatim}
./configure
make
\end{verbatim}
(if you have multiple CPUs try \verb+make -j 4+ or
\verb+make -j 8+. It may need to be issued more than once)
\begin{verbatim}
sudo make install
\end{verbatim}
You need to ensure \texttt{/usr/local/bin} is in your PATH in order
for `jags' to work from a shell prompt.
This will build the default architecture for you Mac: ppc on a G4 or
G5 and i386 or \verb+x86_64+ on an Intel Mac. If you want to build
multiple architecture fat binaries, you will need to ensure that
libtool in the JAGS sources is version 1.5.24 or later. Then you can
use configure commands like
\begin{verbatim}
CXXFLAGS="-arch i386 -arch x86_64" ./configure
\end{verbatim}
Make will then build fat binaries. See the R Mac developers page
\url{http://r.research.att.com/} for instructions to build fat R packages.
A final note on MacOS X builds: do NOT use \texttt{-O3}. It is not optimal
and may find compiler bugs. Apple recommends \texttt{-Os}.
\clearpage
\section{Windows}
\label{section:windows}
These instructions use MinGW, The Minimalist GNU system for Windows.
You need some familiarity with Unix in order to follow the build
instructions but, once built, \JAGS\ can be installed on any PC
running windows, where it can be run from the Windows command prompt.
\subsection{Preparing the build environment}
You need to install the following packages
\begin{itemize}
\item MinGW
\item MSYS
\item NSIS
\end{itemize}
MinGW (Minimalist GNU for Windows) is a build environment for Windows.
There is an official release from \url{http://www.mingw.org}.
However, we used the MinGW distribution that comes as part of the R
tools for windows (\url{http://www.murdoch-sutherland.com/Rtools}),
since the compilers in this distribution match the compilers used to
build the binary distribution of R for windows, as well as the R
packages distributed via CRAN (\url{http://cran.r-project.org}).
We used version 2.11 of \verb+Rtools+. You only need to install the
``MingGW components and tools'', not the other components of
\verb+Rtools+. The installer will also ask if you wish to modify the
Windows PATH. You do not need this.
MSYS (the Minimal SYStem) is part of the MinGW project. It provides a
bash shell for you to build Unix software. These instructions were
tested with MSYS 1.0.10, the last version of MSYS to be bundled with a
Windows installer. The installer can be downloaded from
\url{http://sourceforge.net/projects/mingw/files}. At the end of the
installation process, it will launch a post-install script that will
allow you to use MSYS in conjunction with MinGW.
MSYS creates a home directory for you in
\verb+c:\msys\<version>\home\<username>+, where \texttt{<version>} is
the version of MSYS and \texttt{<username>} is your user name under
Windows. You will need to copy and paste the source files for LAPACK
and JAGS into this directory.
The Nullsoft Scriptable Install System
(\url{http:\\nsis.sourceforge.net}) allows you to create a
self-extracting executable that installs \JAGS\ on the target PC.
These instructions were tested with NSIS 2.33.
\subsubsection{Building LAPACK}
Download the LAPACK source file from
\url{http://www.netlib.org/lapack}. We used version 3.2.1, which is
packaged as \verb+lapack.tgz+. Unpack the file in your home directory.
\begin{verbatim}
tar xfvz lapack.tgz
cd lapack-3.2.1
\end{verbatim}
Copy the file \texttt{INSTALL/make.inc.gfortran} to \texttt{make.inc} in
the top level source directory. Then edit \texttt{make.inc},
replacing the line
\begin{verbatim}
PLAT = _LINUX
\end{verbatim}
with something more sensible, like
\begin{verbatim}
PLAT = _MinGW
\end{verbatim}
Edit the file \texttt{Makefile} so that it builds the BLAS library. The
line that starts \texttt{lib:} should read
\begin{verbatim}
lib: blaslib lapacklib tmglib
\end{verbatim}
Type
\begin{verbatim}
make
\end{verbatim}
The compilation process is slow. Eventually, it will create two static
libraries \verb+blas_MinGW.a+ and \verb+lapack_MingGW.a+. These are
insufficient for building \JAGS: you need to create dynamic link
library (DLL) for each one.
First create a definition file \verb+libblas.def+ that exports all the
symbols from the BLAS library
\begin{verbatim}
dlltool -z libblas.def --export-all-symbols blas_MinGW.a
\end{verbatim}
Then link this with the static library to create a DLL
(\verb+libblas.dll+) and an import library (\verb+libblas.dll.a+)
\begin{verbatim}
gcc -shared -o libblas.dll -Wl,--out-implib=libblas.dll.a \
libblas.def blas_MinGW.a -lgfortran
\end{verbatim}
(If using gcc 3.4, the library should be linked with \verb+-lg2c+
instead of \verb+-lgfortran+)
Repeat the same steps for the LAPACK library, creating an import library
(\verb+liblapack.dll.a+) and DLL (\verb+liblapack.dll+)
\begin{verbatim}
dlltool -z liblapack.def --export-all-symbols lapack_MinGW.a
gcc -shared -o liblapack.dll -Wl,--out-implib=liblapack.dll.a \
liblapack.def lapack_MinGW.a -L./ -lblas -lgfortran
\end{verbatim}
\subsection{Compiling \JAGS}
Unpack the JAGS source
\begin{verbatim}
tar xfvz JAGS-2.0.0.tar.gz
cd JAGS-2.0.0
\end{verbatim}
and configure JAGS
\begin{verbatim}
./configure LDFLAGS="-L/path/to/import/libs/"
\end{verbatim}
where \verb+/path/to/import/libs+ is a directory that contains the
import libraries (\verb+libblas.dll.a+ and \verb+liblapack.dll.a+).
This must be an {\em absolute} path name, and not relative to
the JAGS build directory.
Normally you will want to distribute the blas and lapack libraries
with JAGS. In this case, put the DLLs and import libraries in the
sub-directory \verb+win32/include+. They will be detected and included
with the distribution.
Make sure that the file \verb+makensis.exe+, provided by NSIS, is in
your PATH. For a typical installation of NSIS:
\begin{verbatim}
PATH=$PATH:/c/Program\ files/NSIS
\end{verbatim}
Then type
\begin{verbatim}
make win32-installer
\end{verbatim}
The self extracting archive will be in the subdirectory \verb+win+.
Note that you must go straight from the configure step to \texttt{make
win32-installer} without the usual step of typing \texttt{make} on
its own. The \texttt{win32-installer} target resets the installation
prefix, and this will cause an error if the source is already
compiled.
\subsection{Building on 64-bit windows}
The build instructions for 64-bit windows are similar to the
instructions for 32-bit windows. Instead of the MinGW tools that come
with R, we use a 64-bit compiler from the MinGW-w64 project
(\url{http://www.sourceforge.net/projects/mingw-w64}). The
distribution used to build JAGS-2.0.0 was
\verb+mingw-w64-1.0-bin_i686-mingw_20100322.zip+, which is also the
compiler used to build the 64-bit Windows binary distribution of
R-2.11.0. This is actually a cross-compiler. It will run under MSYS
--which is still 32-bit -- but will produce 64-bit code.
Most binary distributions of MinGW-w64 use dynamic linking to runtime
libraries. This is inconvenient, as it means that the required runtime
libraries must be distributed with JAGS. Failure to do so will either
result in an installation that is either completely non-functional or
will crash. To force the compiler to use static linking, delete any
import libraries (files ending in \verb+.dll.a+). In the case of the
\verb+mingw-w64-1.0-bin_i686-mingw_20100322.zip+ distribution, we had
to remove \verb+libssp.dll.a+. Note that there is currently no way to
avoid dynamic linking to the gcc runtime library (see below).
In order to build the BLAS and LAPACK libraries, you need to append the
prefix \verb+x86_64-w64-mingw32-+ to all the tools. This means you need
to edit the entries FORTRAN, LOADER, ARCH, and RANLIB in the Makefile,
as well as modifying the name of \verb+dlltool+ and \verb+gcc+ when
building the DLLs for BLAS and LAPACK.\footnote{Although we are using
a cross-compiler, you cannot cross-build 64-bit BLAS and LAPACK on a
32-bit Windows system. This is because the build process includes compilation
of test programs which must be run.}
To build \JAGS\ you do not need to edit any makefiles. Just add the
configure option
\begin{verbatim}
--host=x86_64-w64-mingw32
\end{verbatim}
to use the cross-compiler. You may also wish to add the linker flag
\begin{verbatim}
LDFLAGS=-Wl,--enable-auto-import
\end{verbatim}
in order to suppress some warnings from the linker, although these
seem to be harmless.
The \JAGS\ binary built in this way will be dynamically linked to the
C runtime library \verb+libgcc_s_sjlj-1.dll+, which is part of the
MinGW-w64 distribution. You will find it in the \texttt{bin}
directory. You should put a copy of this DLL in the
\texttt{win/runtime} directory so that it is included in the
installer.
Finally, in order to build the NSIS installer, you should use the make
target \verb+win64-installer+ instead of \verb+win32-installer+.
\end{document}

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks