Welcome to the most active Linux Forum on the web.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 11-04-2006, 11:10 AM   #1
LQ Newbie
Registered: Dec 2005
Posts: 21

Rep: Reputation: 15
Problems using the GNU Scientific Library

Hello everyone,

I have been trying to use the GSL in C++, but my programs give errors. Somehow I don't include it the right way. Consider the following code:

#include <iostream>
#include "gsl/gsl_cdf.h"

using namespace std;

double d_x, d_mu, d_sigma, d_opp;
bool bool_input;
double func_normalcdf(double d_x, double d_mu, double d_sigma)
	return (gsl_cdf_gaussian_P(d_x, d_sigma) + d_mu);

double func_InvNorm(double d_opp, double d_mu, double d_sigma)
	return (gsl_cdf_gaussian_Pinv(d_opp,d_sigma) + d_mu);

int main()
	if (bool_input == 0)
	if (bool_input == 1)
G++ gives the following error:

Alkibiades@localhost:~/C++> g++ try.cpp -o try
/tmp/cc92hYEo.o: In function `func_InvNorm(double, double, double)':
try.cpp.text+0xaa): undefined reference to `gsl_cdf_gaussian_Pinv'
/tmp/cc92hYEo.o: In function `func_normalcdf(double, double, double)':
try.cpp.text+0xec): undefined reference to `gsl_cdf_gaussian_P'
collect2: ld returned 1 exit status
I don't get it. I have been using the correct syntax for the functions, as this is what the GSL manual says:

— Function: double gsl_cdf_gaussian_P (double x, double sigma)
— Function: double gsl_cdf_gaussian_Q (double x, double sigma)
— Function: double gsl_cdf_gaussian_Pinv (double P, double sigma)
— Function: double gsl_cdf_gaussian_Qinv (double Q, double sigma)

These functions compute the cumulative distribution functions P(x), Q(x) and their inverses for the Gaussian distribution with standard deviation sigma.
Any ideas?
Thank you in advance!

Yours, Alkibiades
Old 11-04-2006, 11:42 AM   #2
LQ Addict
Registered: Jul 2003
Location: London, UK
Distribution: Slackware
Posts: 7,464

Rep: Reputation: Disabled
You need to link that library, because it contains the definitions for those functions (the header files usually only contain the function prototypes). Edit: as per the documentation, you just use gcc's -l option, specifying "gsl":

Just a quick thing: you really didn't need to declare those global variables. You can just put your bool_input in main() and get rid of the others (especially since you're not even using them!). The parameters declared in the function headers are local variables for those functions.

Last edited by Nylex; 11-04-2006 at 12:02 PM.
Old 11-04-2006, 02:43 PM   #3
LQ Newbie
Registered: Dec 2005
Posts: 21

Original Poster
Rep: Reputation: 15
Thanks a lot! It works fine now!



Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
how to not use GNU "C" Library astropirhana Programming 8 08-24-2006 01:18 PM
GNU based c++ cross compiler unable to link c library k_taid Programming 1 06-29-2005 10:38 AM
GNU Library Archives wood@addanc Programming 1 06-28-2005 05:05 PM
Problems with GNU linker ld chip1081 Linux - Software 5 10-15-2004 05:46 PM
GNU make problems MacDaddy Linux - General 9 08-26-2001 03:09 PM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 03:33 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration