AD Model Builder/Installing Open-Source ADMB in Linux

From QERM Wiki
Jump to: navigation, search

NOTE: both the scripts and the installation instructions at have improved since Motoki wrote this fine description of his installation process. However, it may still prove useful so will remain in place.

I (Motoki) went through some steps to get the open source ADMB working for my computer (Ubuntu 8.04; gcc 4.2; GNU bash 3.2). It may work for Mac OS X but I haven't tested anything.

First, download and unzip the proper source files into a directory (say in my case /home/apewu/ADMB). This will set the binary files in /home/apewu/ADMB/bin, the libraries in /home/apewu/ADMB/lib and so on.

Next, we need to define the environmental variable ADMB_HOME as the directory of your ADMB files. I also created aliases for the necessary binary files to run an ADMB program (tpl2cpp and mygcco) for convenience. This can be all done by adding the following code in your .bashrc file in the home folder.

export ADMB_HOME=/home/apewu/ADMB
alias tpl2cpp='/home/apewu/ADMB/bin/tpl2cpp'
alias mygcco='/home/apewu/ADMB/bin/mygcco'
alias mygccs='/home/apewu/ADMB/bin/mygccs'

So now these commands will be available to you everytime you start the bash shell.

Now we need to fix the mygcco a bit, since it doesn't recognize the -o option well. So I put this option in the front of the gcc command so it would recognizee it. The following is my mygcco file.

# for compiling from tpl2rem
if [ ! -n "$ADMB_HOME" ]; then
    echo you must define the environment string ADMB_HOME
    g++  -o$1.out -g -v $1.cpp -I. -fpermissive -I/${ADMB_HOME}/include \
      -L/${ADMB_HOME}/lib -DUSE_LAPLACE -D__GNUDOS__ -Dlinux -DOPT_LIB -O3 \
      -ldf1b2stub -ladmod -ladt -lado -ldf1b2stub -ladmod -ladt -lado \
#      -ldf1b2o -ladmod -ladt -lado -ldf1b2o -ladmod -ladt -lado \

Then by using tpl2cpp and mygcco in succession should compile the executable with an .out extension. You could get rid of the -v option since it's annoying. A disclaimer is that, the filename should be lowercase for all this to work.

Finally, we can make bash function that can do both these steps in one fly.

# does tpl2cpp and mygcco of a .tpl file!
tpl2cpp $1
mygcco $1

Put this in /home/apewu/ADMB and alias it for a one step compilation and running of ADMB code.

We could then use the system() command to really inline it into R for interacting with ADMB.

~ last updated 11/28/08

Personal tools