Using GSL in Xcode

Discussion in 'Mac Programming' started by w0ngbr4d, Apr 1, 2006.

  1. macrumors regular

    Jan 10, 2006
    Findlay, OH
    For a school project, I need to use the GNU GSL library to do some calculations. I installed fink and downloaded the gsl library and installed it.

    In Xcode, I went to get info on the project and under the "Header Search Paths" I typed in "/sw/include/" so Xcode would see the gsl header files.

    The project compiles just fine, but when I try to run it, I get "ZeroLink: unknown symbol '_gsl_rng_default'"

    What else to I have to setup in XCode to get it to use this library?



    EDIT: Here's the code

    #include <stdio.h>
    #include <gsl/gsl_rng.h>
    #include <gsl/gsl_randist.h>
    int main (int argc, const char * argv[]) {
        // insert code here...
    	const gsl_rng_type *T;
    	gsl_rng *r;
    	T = gsl_rng_default;
    	r = gsl_rng_alloc(T);
        printf("Hello, World!\n");
        return 0;
  2. thread starter macrumors regular

    Jan 10, 2006
    Findlay, OH
    Ok, I got the GSL to work with gcc on the command line. This is how I have to compile it:

    gcc main.c -lgsl

    Is there a way to append the -lgsl to the compile line in XCode?

    Thanks for you help.

  3. macrumors 603


    Oct 16, 2003
    Try to change development style from development to deployment (or turn off ZeroLink), and see what happens.

    Getting the effect of -lgsl (link in the gsl library) should be possible, but I don't know exactly how.
  4. thread starter macrumors regular

    Jan 10, 2006
    Findlay, OH
    Yeah did some Googling and figured out how to add the library file to XCode. Here's how to do it:

    Project Menu
    Add To Project...
    Select the library file...
    Click OK

    It compiled and ran.

    Just thought I would add how I fixed this incase anyone else needs to do this at some point.

    Thanks again.

  5. macrumors 603


    Oct 16, 2003
    Good thinking.
  6. macrumors newbie

    Feb 5, 2009
    Did you have to compile it first to get the library files or did you just grab the ones from fink or macports?

    I went to the gsl site and grabbed the source, ran "./configure --disable-shared" to configure it and "make" to compile it and now I have the libgsl.a file.
  7. macrumors newbie

    Feb 2, 2010
    GSL libraries in hidden folders?

    Dear all,

    thanks to the hints in this forum I managed to compile the GSL on my Mac 10.6. Thank you very much!

    However, I figured out by chance that the libraries end up in hidden .libs folders all over the place. Un-hiding the folders and then adding the libraries to an Xcode project works fine, but why are these hidden in the first place?

    Is there a more apropriate way to add the libraries?

    Btw while getting GSL to work I came across some hints that may be useful for others.

    - to compile GSL, Xcode must be installed including the UNIX developer tool option
    - gcc and make are in Developer/usr/bin. This path is not included per default in the search path in Terminal
    - gcc and make don't like blanks in folder name. Anything in e.g "/MyCode/gsl" will compile but "/My Code/gsl" will not.

Share This Page