Compiling Mex files
From BioNetWiki
Mac OSX
Should already have pre-installed: Terminal (bash), gcc, tar
Additionally install: CMake (download universal binary from here.)
Determine the platform architecture for which MatLab was installed using MatLab-> About MatLab. If the description is maci or maci64, the architecture is x86 or x86_64 respectively. Installing CVODE Create an accessible parent folder named cvode and download a tarball of the latest version of CVODE (from here). Open bash and uncompress the tarball. In the same parent folder, create two folders builddir and instdir.
$ pwd /Users/username/cvode/ $ ls cvode-2.6.0.tar.gz $ tar -zxvf cvode-2.6.0.tar.gz $ mkdir builddir instdir
In the builddir folder, invoke the CMake GUI targeted at the cvode-2.x.y folder.
$ cd builddir $ cmake-gui /Users/username/cvode/cvode-2.6.0
Click on Configure. When done the first time, one has to choose the generator. Choose UNIX Makefiles.
From the options generated, edit CMAKE_OSX_ARCHITECTURES to x86_64 (or x86, as the case may be).
Also edit CMAKE_INSTALL_PREFIX to the instdir path, i.e. /Users/username/cvode/instdir.
Configure again. Click on Generate and quit the interface when complete.
Back at the bash prompt in builddir, execute make and make install.
$ make $ make install
Enter the folder where the BioNetGen model xyz.bngl resides. Make sure it contains the command writeMexfile() in the actions section. Executing the model generates the M-file (xyz.m) and the paired C-file (xyz_cvode.c).
$ perl /Users/username/BioNetGen/BNG2.pl xyz.bngl
In MatLab, make sure to add the CVODE parent folder and its subfolders to the MatLab Path (File->Set Path->Add with subfolders). Change to the folder where the paired M-file and C-file reside and compile with the mex command. Make sure to link the include and lib paths with the -I and -L tags respectively.
>> mex –lsundials_nvecserial –lsundials_cvode –lm –I/Users/username/cvode/instdir/include –L/Users/username/cvode/instdir/lib xyz_cvode.c
Use the M-file as a typical MatLab function file. See Mex code generator for details.
>> xyz.m
(Verified on iMac Intel Core 2 Duo 64-bit architecture, OSX 10.5.8, CMake 2.8.6, CVODE 2.6.0 and MatLab 7.10.0.499 (R2010a)

