Tom Frese, Dec. 1, 2000. frese@ecn.purdue.edu


Compiling the code requires that you have matlab
installed and know the location of your matlab
installation directory.



I. COMPILING:
--------------------------------------------------------
Note: After compiling, you will need to follow the instructions
   in section II before running the code.

The first step is to modify src/Makefile. The Makefile
currently supports HP-UX, Solaris and Linux (see notes
for Linux at the end of this file). 

If you have a different Unix OS, it should be very easy to modify
the Makefile for that also (you will need to modify 
the entries below the CONFIG Section)

Assuming you run HP-UX, Solaris or Linux:

1) Set the OS variable.

2) Set the MATLAB_BASE variable to the location of your 
    matlab installation directory (i.e. the one that has
    subdirectories such es extern and include)

3) Set the CC_OS (e.g. CC_HP-UX) variables to the compiler that
    you wish to use. 

4) Depending on your compiler, modify the CFLAGS_OS for your OS.
    The code uses ansi C specifications. 


After modifying the Makefile, make sure you're in the src
directory and type 'make' at the command prompt. 
The program should compile without errors or warnings and 
generate the routine 'cbp' in ../, i.e. the main directory.

If you get warnings about missing 'mat.h', then your include
path in the Makefile isn't set correctly.

If you get messages about missing libraries (e.g. mi.so or
something like that), you might need to add something like
-lmi to the LIBS_OS line in the Makefile. (some libs include
other matlab libs and those dependencies depend somewhat
on the matlab version).




II. SETTING LIBRARY RUN-PATH
---------------------------------------------------------

In order to run the cbp program, you will need to tell
your shell where to locate the dynamic matlab libraries
at runtime.

1) In HP-UX, you can just define a linker variable

   setenv LDOPTS +b:

   in your .cshrc. This setting tells the system to
   load the dyn. library from the path that was specified
   with the -L flag at compile time.

   Make sure that you reload your
   environment (e.g. source .cshrc) before continuing.
   You might need to recompile cbp once more after
   including this setting (cd src, make clean, make). 


2) In Solaris or Linux, set the environment variable 
   LD_RUN_PATH to the directory containing 
   the matlab libraries, e.g. for Linux in your .cshrc put a line
   
      
   setenv LD_RUN_PATH /usr/local/matlab/extern/lib/lnx86
   
   or for Solaris, put something like

   setenv LD_RUN_PATH /usr/local/matlab/extern/lib/sol2

   where /usr/local/matlab should be replaced by your matlab
   install directory.
 
   Make sure that you reload your
   environment (e.g. source .cshrc) before continuing, i.e. trying
   to run cbp.




III. ISSUES
----------------------------------------------------
I've tested compilation on HP-UX (HP ansi cc compiler), 
Linux (gcc, libc5 version) and Solaris (Sun cc compiler).
It's not always easy to get the Matlab libraries linked in 
and to be found at runtime. For example, I had a strange
problem under HP-UX, where I could compile but when I
wanted to run the program, I would get an error:

/usr/lib/dld.sl: Call to mmap() failed - TEXT /usr/lib/pa1.1/libM.1
/usr/lib/dld.sl: Permission denied
IOT trap (core dumped)

This indicates, that one of the matlab libraries isn't found
at runtime. This happened despite setting all the environment
variables etc. as described below. It seemed, that the 
libraries were on some filesystem that the HP-UX linker
refused to see, although I gave it the specific path. This
was fixed by copying the libraries into the working directory
(CBP_PU/src) and setting the paths accordingly.


Another potential problem is the getopt.h include file
that is used to parse the command-line options.
If you use the cc compiler under HP-UX or on a Sun, you
don't need to include getopt.h. 
For gcc, you will need an #include <getopt.h>. For
Linux, this is done in the header of cbp.c by putting
#ifdef __linux__
  #include <getopt.h>
#endif

However, on HP-UX and Solaris, newer versions of GNU gcc 
couldn't find getopt.h.
I've included getopt.c and getopt.h in src/GETOPT, you might
need to include these in cbp.c and add getopt.o to the OBJS line
in the Makefile. (I haven't tested this).



IIIb. LINUX ISSUES
-----------------------------------------------------

In glibc based Linux systems such as RedHat 5 and higher,
the dynamic matlab libraries conflict with the glibc libraries.
Thus, it is necessary, to link the file with libc5 instead of
glibc. To do this, you must first install compiler and runtime
libraries for libc5. Also, you must install a libc5 gcc compiler
(this compiler is called i-486-linuxlibc5 and won't interfere 
with your regular gcc compiler).
The packages that you need are

gcc-libc5-2.7.2.3-3.i586.rpm       libc5-devel-5.4.46-1.i586.rpm
gcc-libc5-c++-2.7.2.3-3.i586.rpm   libc5-profile-5.4.46-1.i586.rpm
gcc-libc5-objc-2.7.2.3-3.i586.rpm  libc5-static-5.4.46-1.i586.rpm
libc5-5.4.46-1.i586.rpm            libg++-libc5-2.7.2.8-1.i586.rpm
libc5-debug-5.4.46-1.i586.rpm      libg++-libc5-devel-2.7.2.8-1.i586.rpm

which can be found on www.rpmfind.net.

