Ubuntu Forums ubuntu.com - launchpad.net - ubuntu help  

Go Back   Ubuntu Forums > The Ubuntu Forum Community > Other Community Discussions > Development & Programming > Programming Talk
Register Reset Password Forum Help Forum Council Search Today's Posts Mark Forums Read

Programming Talk
This forum is for all programming questions.
The questions do not have to be directly related to Ubuntu and any programming language is allowed.

 
Thread Tools Display Modes
Old October 3rd, 2006   #1
Juanito
5 Cups of Ubuntu
 
Join Date: Aug 2005
Beans: 14
Undefined Reference for GSL library calls

Hey guys,

I'm in a bit of a time-bind, so I thought I'd ask here after spending 2 hours scouring the internet for an answer.

I am using the GNU Science Library

http://www.gnu.org/software/gsl/manu...ng-and-Linking

After including the proper header files
#include <gsl/gsl_rng.h>
#include <gsl/gsl_randist.h>


After pressing Build in KDevelop or Anjuta, I'm getting errors like...

undefined reference to `gsl_ran_multinomial'

From what I've read, it's something about linking? I'm used to good ol' java and visual studio, so I have no clue what to do.

Thanks for your patience!
Juanito is offline   Reply With Quote
Old October 4th, 2006   #2
hod139
Fresh Brewed Ubuntu
 
Join Date: Jul 2005
Beans: 1,537
Ubuntu 8.04 Hardy Heron
Send a message via AIM to hod139
Re: Undefined Reference for GSL library calls

You are correct, it is a linking issue. I'm not sure how to specify external libraries in Kdevelop or Anjunta, but on the command line you would do this:

Code:
gcc myfile.c -lgsl
the "-l" flag tells gcc to link against the gsl library. You will need to tell an IDE to also link against gsl.

You most likely will also want -lm (the math lib).
__________________
When I invented the Web, I didn't have to ask anyone's permission.
~Tim Berners-Lee on Net Neutrality
-------------------------------------
Visit the Ubuntu Programming IRC-channel at #ubuntu-programming (chat.freenode.net).
hod139 is offline   Reply With Quote
Old June 5th, 2008   #3
jwilley44
5 Cups of Ubuntu
 
Join Date: Jun 2008
Beans: 16
Re: Undefined Reference for GSL library calls

Hello, I had the same problem. I tried compiling with -lgsl and I got a bunch of errors. The errors were of the form:

/usr/lib/gcc/x86 64-linux-gnu/4.2.3/../../../../lib/libgsl.so undefined refernce to `cblas_csyrk'

with the last part between the ` and the ' varying.

Thanks in advance
jwilley44 is offline   Reply With Quote
Old June 5th, 2008   #4
WW
Fresh Brewed Ubuntu
 
Join Date: Oct 2004
Beans: 1,532
Re: Undefined Reference for GSL library calls

The best way to get the correct arguments to link the GSL library is with the pkg-config command:
Code:
$ pkg-config --libs gsl
That will print the options required to link the GSL library. You can also use the --cflags option to get the correct compiler options:
Code:
$ pkg-config --cflags gsl
(That may just print a blank line, meaning no special options are required, since the header files are in a standard directory.)

To compile and link a program that is contained in a single C file that uses GSL:
Code:
$ gcc myprogram.c `pkg-config --cflags --libs gsl` -o myprogram
Or, to compile and then link,
Code:
$ gcc -c myprogram.c `pkg-config --cflags gsl`
$ gcc myprogram.o `pkg-config --libs gsl` -o myprogram
I don't use KDevelop or Anjuta, but I am sure there is a standard way to tell them to use the required compiler options.
WW is offline   Reply With Quote
Old June 17th, 2009   #5
abhinandkr
First Cup of Ubuntu
 
Join Date: Jun 2009
Beans: 1
Re: Undefined Reference for GSL library calls

Yes it works!
And, you can simply create a shell file to execute that compile and link statement. Give the o/p file as a.out if required.
abhinandkr is offline   Reply With Quote

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 08:09 PM.


vBulletin ©2000 - 2010, Jelsoft Enterprises Ltd. Ubuntu Logo, Ubuntu and Canonical © Canonical Ltd. Tango Icons © Tango Desktop Project. lingonberry