so i was trying to compile some C code on my server at school that involves the math and the GNU Scientific Library (gsl) libraries. that is, the source has the following lines:
<pre class="src src-C"><span style="color: #b0c4de;">#include</span> <span style="color: #ffa07a;"><stdio.h></span>
#include <math.h> #include <gsl/gsl_integration.h>
those link the header files. however, when compiling, gcc would complain that they can’t see functions such as sqrt, abs, etc, from the math library. it also complains about my call to a function from the gsl library. i googled the math library stuff and realized i need to pass the ‘-lm’ argument in gcc for the math library. similarly, i saw somewhere that refers to the ‘-gsl’ argument. however, this did not work for me. i tried many things. some more googling, i found this thread that shows the ‘pkg-config’ command that shows exactly what arguments u need for which library.
So, i get:
<pre class="src src-sh">$ pkg-config --libs gsl
-lgsl -lgslcblas -lm
so i just need to execute:
<pre class="src src-sh">gcc -lgsl -lgslcblas -lm myprogram.c
i really don’t understand how the GNU compilers work. on my mac, i don’t have to pass those arguments. on my debian server, i need to. at first i thought that including the header was enough. will need to learn more about this stuff.
PS I also remember using this command when i had a hard time compiling shell-fm on my mac os x.
UPDATE: so on my mac os x, after installing gsl, i need to use ‘gcc -lgsl myprog.c’ to use the gsl library. things are fine now. I also want to note that i could not compile GSL form source on my debian server…had to rely on apt-get.