I've been having a harrowing time lately just trying to get several C programs compiled because I can't find where the libraries are located and pkg-config seems to be out of order.
I installed GNU GSL like this:
wget ftp://ftp.gnu.org/gnu/gsl/gsl-1.15.tar.gz
tar xvzf gsl-*gz
cd gsl-1.15
./configure
make
sudo make install
Apparently it installed in /usr/local/lib
which is a non-standard place? (1) What is a standard place? (2) How would I get it to install there?
And I can't manage to compile a simple program that uses this library:
$ gcc gsl_erf.c -o gsl -I/usr/local/lib -L/usr/local/lib
/tmp/cc3WD9Zq.o: In function `main':
gsl_erf.c:(.text+0x24): undefined reference to `gsl_cdf_gaussian_P'
collect2: error: ld returned 1 exit status
Now, with pkg-config :
pkg-config --libs --cflags gslPackage gsl was not found in the pkg-config search path.
Perhaps you should add the directory containing `gsl.pc'
to the PKG_CONFIG_PATH environment variable
No package 'gsl' found
So I did add the directory:
PKG_CONFIG_PATH=/usr/local/lib/pkgconfig
But no luck yet! 🙁 pkg-config still gives me the same message as above. (Perhaps you sh ...
)
This is a more general problem I face regularly when I have to compile some C program. I would love a general solution for:
- Where and how do I install my C libs? (Perhaps the same place yum installs them?)
- How do I correct/configure and use pkg-config
Update : I tried one of the answer's suggestions below and running the compiled program gives me this : ./gsl_app: error while loading shared libraries: libgsl.so.0: cannot open shared object
Best Answer
It's a standard place, but sometimes systems are configured presuming that you are not going to build-install anything, and so it is left out of the linker cache path.
That is generally a bad idea, esp. if there are potentially distro packages -- now, or down the line -- that conflict. Stick with /usr/local.
Check to see if
/usr/local/lib
is in ld.so.cache by runningldconfig -v 2>&1 | grep /usr/local
. If you don't get any output, create a file/etc/ld.so.conf.d/local.conf
with one line:Run that
ldconfig
line again and this time you should see it. You need to run ldconfig every time you build and install a library from source.Because you have to pass the
pkg-config
parameters to the compiler. First, you need to find the actualgsl.pc
.I think it is more likely in
/usr/local/lib/pkgconfig
, and not/usr/local/pkgconfig
as you say. Trypkg-config --list-all | grep gsl
and see if it's found. If notexport PKG_CONFIG_PATH=/usr/local/lib/pkgconfig:$PKG_CONFIG_PATH
(or whatever the directory with gsl.pc is) and try again. When you get that right, you may want to add it somewhere in, e.g.,/etc/profile.d
.Now, to actually compile:
You don't need to include
-I
and-L
yourself; that's whatpkg-config
is for, although all you were likely missing before was-lgsl
.