Question

I have this trivial C program, but just can't it to link correctly.

here is the program,

#include <gsl/gsl_cdf.h>
#include <stdio.h>

int main()
{
   double bottom_tail = gsl_cdf_gaussian_P(-1.96, 1);
   printf("Area between [-1.96, 1.96]: %g\n", 1-2*bottom_tail);
}

at the shell, I'm doing:

gcc gsl_erf.c -o gslTest -I/usr/local/include/gsl -L/usr/local/lib

I know for sure that the gsl_cdf.h header file is in /usr/local/include/gsl, similarly I know that the .sos are in /usr/local/lib

the linker, gcc backend?, complains that I have an undefined reference to gsl_cdf_gaussian_P

I thought my order was incorrect, so I also tried:

gcc -I/usr/local/include/gsl -L/usr/local/lib gsl_erf.c -o gslTest

but this craps out as well. What am I doing wrong? :(

Was it helpful?

Solution

You have to tell the compiler to actually link with the library you're using: you need an -l option, probably something like -lgsl. (Take the name of the .so file, remove the .so suffix and lib prefix, and that's what to put after -l.)

The -L option tells the linker where to find libraries, but doesn't direct it to actually link with anything — just like the -I option tells the compiler where to find headers, but doesn't actually #include any code.

OTHER TIPS

You don't actually ask for the libraries on the compile command. You provide a search path with "-L" but you don't actually request the libraries. You need something like "-lgsl" as well (assuming the library is libgsl.so).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top