PDA

View Full Version : Using GSL in Xcode




w0ngbr4d
Apr 1, 2006, 03:14 PM
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?

Thanks.

w0ngbr4d

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;

gsl_rng_env_setup();

T = gsl_rng_default;
r = gsl_rng_alloc(T);

printf("Hello, World!\n");
return 0;
}



w0ngbr4d
Apr 1, 2006, 05:36 PM
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.

w0ngbr4d

gekko513
Apr 1, 2006, 05:45 PM
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.

w0ngbr4d
Apr 1, 2006, 05:49 PM
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.

w0ngbr4d

gekko513
Apr 1, 2006, 05:52 PM
Just thought I would add how I fixed this incase anyone else needs to do this at some point.
Good thinking.

simpleH
Feb 5, 2009, 09:55 AM
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.

ChrisHH
Feb 2, 2010, 04:12 PM
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.