Installing GSL For Dummies

in Genius Bar edited September 2014
Ok, so I'm just getting into Objective-C and XCode after having learned programming almost exclusively on Windows (with a hint of Unix for flavoring). I want to install GSL, and have the latest distribution, but from there, I'm stuck. I'm sadly ignorant of Mac terminal commands, and never really used unix enough to be able to sort it out myself easily. Can anyone provide a step by step walkthrough for a typical installation of GSL, for use with XCode 3 under Leopard?

I should note that I have googled this already, and everything I came up with assumed that the user already knows how to use the terminal well. Kind of a plague, I think, this assumption that the CS industry has that all programmers must automatically know unix. Oh well. I have to admit, I'm somewhat embarrassed to ask for help on this, but I figure that someone else has probably run into the same problem, so I'll be serving the Greater Good (yeah, right) in doing so.




  • Reply 1 of 5
    MarvinMarvin Posts: 14,834moderator
    You can use one of the GUI library installers like:

    Install Fink, then Fink commander. When you open Fink commander, it will show a list of packages. Choose the right one and you can install a binary or build and install source. The 10.4 binary should work on 10.5.

    You should then be able to include the library in your source code in XCode using #include gsl.h or #import gsl.h or something like that. You may need to add an include directory to your project settings.
  • Reply 2 of 5
    celemourncelemourn Posts: 769member
    Ok, well, I got it working, but it's a pain in the butt from within XCode. I can't help but think there must be an easier way to link to it, but I haven't figured that out yet. Here is how I THINK it can be done, every time:

    1. Download and decompress the latest build of GSL. I used 1.11.

    2. Drag the folder (which you just expanded) containing GSL to the Desktop.

    3. Go into your Utilities folder in the Applications folder, and open the program called, "Terminal".

    4. Check to make sure the title of the window says 'bash' somewhere. When the command line pops up, enter the following:


    cd ~

    cd Desktop

    cd gsl*



    sudo make install

    This will, by default (as of version 1.11 of GSL anyway) install the libraries to the folder /usr/local/lib, with the headers being found in /usr/local/include. You'll have to add these search paths to xcode manually, as well as add the line

    -lgsl -lgslcblas

    to the additional linker flags settings. There is a good walkthrough HERE.

    ***Info below accurate as of 12MAY08***

    Note that this is for XCode 3.1, which you can only get by downloading and installing the iPhone SDK. This is a free download from Apple, and does requires that you register with the iPhone developer program, but you do NOT have to pay the $99 fee for testing and stuff. Just register, and when you get to the screen where it mentions money, hit the cancel button, and you should be redirected to the iPhone developers page, with the download links enabled.


    All in all, this is really messy, and it would be nice if there were an easy way to do all this. Even using MacPorts was absurdly complicated and didn't work for me (I never tried Fink). It would be nice if someone could compile GSL into an xcode framework or something... would that work?
  • Reply 3 of 5
    celemourncelemourn Posts: 769member
    oh, one more note, I got the GSL package from the GNU FTP server, HERE.

  • Reply 4 of 5

    Thanks for posting this.  I must have read 10 articles before I found yours.  And yes...they were wanting me to do stuff with Fink, etc.  Your instructions work perfectly on OS X mavericks and the latest GSL library at this time which is 1.16.  


    Since there is a dead link to that walkthrough, let me supplement this post:


    Add #import <gsl/gsl_rng.h> to your code to run sample code below


    then go to Build Settings in xcode and  add /usr/local/include to the Header Search Paths and /usr/local/lib to the Library Search Paths




    then go to Other Linker Flags and add -lgsl -lgslcblas




    Run a sample GSL program.  I found this one on the internet and it works:



            const gsl_rng_type * T;

            gsl_rng * r;


            int i, n = 10;




            T = gsl_rng_default;

            r = gsl_rng_alloc (T);


            for (i = 0; i < n; i++)


                double u = gsl_rng_uniform (r);

                printf ("%.5f\n", u);



            gsl_rng_free (r);

  • Reply 5 of 5

    I haven't use xcode before at all. I need this to generate Gaussian random number for a project. Could you please let me know how to access Build settings? 

Sign In or Register to comment.