Search code examples
ubuntug++ubuntu-14.04autotoolsgsl

Difficulty linking math and GSL in Ubuntu


I have a distro that I wrote a while ago and happily installed on Fedora, Ubuntu, and OSX. I'm now trying to get it to install on Ubuntu 14 LTS, but am running into some difficulty.

I believe that I have installed the requisite libraries:

$ sudo apt-get install g++ gsl-bin gsl-ref-html libgsl0-dev

And have let gsl-config tell me what to use in my configure:

$ gsl-config --prefix
/usr
$ gsl-config --libs
-L/usr/lib -lgsl -lgslcblas -lm
$ gsl-config --cflags
-I/usr/include

But when I configure, it doesn't seem to be finding the math and GSL libraries:

$ ./configure --prefix /usr LDFLAGS='-L/usr/lib -lgsl -lgslcblas -lm' CPPFLAGS=-I/usr/include
...
checking for gsl_eigen_symm in -lgsl... no
checking for gsl_matrix_view_array in -lgslcblas... no
…
checking for floor... no
checking for pow... no
checking for sqrt... no
...

And rather expectedly, the make command fails in linking:

$ make

…
g++  -g -O2 -lgsl -lgslcblas -L/usr/lib -lgsl -lgslcblas -lm -o neuron neuron.o dataset.o twoset.o utility.o stats.o vector_ops.o matrix.o model.o iterative.o network.o simpleprop.o bareprop.o backprop.o logistic.o regressnet.o dfa.o ldfa.o qdfa.o  
network.o: In function `Network::reportCondNum(std::ostream&)':
/home/craign/neuron-2.63/src/network.cpp:636: undefined reference to `gsl_matrix_view_array'
… bunch of other undefined reference errors

Any ideas?

Many thanks in advance, Craig


Solution

  • This command line:

    g++ -g -O2 -lgsl -lgslcblas -L/usr/lib -lgsl -lgslcblas -lm -o neuron neuron.o ...

    is completely backwards. (Read this or this to understand why the order of objects and libraries on the link line matters.)

    You probably want:

    ./configure --prefix /usr LIBS='-lgsl -lgslcblas -lm' ...