How to use GNU Scientific Library (GSL) with Matlab 32/64

This is what I did to get GSL to work with Matlab 2008a. I used Visual Studio 2008. This is a modification of instructions found here.

1.       Download GSL from here.

 

2.       Make sure you have Visual Studio 2008/2010 installed (full version).

 

3.       Download the project files created by Brian Gladman here. Uncompress them in the root gsl folder. You will be asked to overwrite some gsl files. Say yes.

 

4.       If you are under a 32-bit architecture, you may be able to use a pre-compiled binary for windows. Download GSL for Windows from here.

 

5.       Compile GSL using Visual Studio.

a.       You need to first compile gslhdrs.c using the project file. Then run the .exe file to collect the headers.

b.      Compile the static and dynamic libraries using

1.       Dynamic: gsldll\gsldll.vcproj

2.       Static: gsllib\gsllib.vcproj

Make sure you compile the libraries for the appropriate architecture of your system I compiled both the Debug and Release versions.

 

6.       Go to Start Menu > Control Panel > System. Click on the Advanced tab. Click the button Environment Variables at the bottom of the tab. Add the following variables:

a.       INCLUDE <gsl_folder>\gsl

b.      LIB <gsl_folder>\build.vc9\lib

If these variables already exist, append contents above after the existing contents. Be sure to separate the paths with a semicolon. If you replace the existing contents, some programs on your system may cease to work properly. You may make these modifications in the user or system depending on the desired scope of the installation.

 

7.       Run the mex -setup command in Matlab. Select Visual Studio 2008 as your desired C compiler. This will create a file called mexopts.bat in the user account's Matlab folder (e.g., <user>\AppData\Mathworks\MATLAB\2008a\mexopts.bat).

a.       Find and edit the file with a text editor.

b.      Find the line that begins set LINK_FILE.

c.       At the end of this line, append gsl.lib cblas.lib.

If you run mex -setup after you modify this file, this change will be overwritten and must be repeated.

When compiling your code, add -lgsl lcblas switches. In case matlab cannot file the .h files, you can also include a I<gsl_folder> switch. You may also include paths to the .dll or .lib files by the L switch.

 

Back