So, I just did a fresh install of ubuntu 11.10, and am in the process of reinstalling gsl. For some reason, my old make file seems not to work, and am trying to figure out how to change it. Last time I had a similar problem, people in here were very helpful in figuring it out, so I've got my fingers crossed :)

The call to g++ is:

g++ -Wall  -lgsl -lgslcblas -lm  -L/usr/lib -I /usr/include/gsl -o main main.o neuron.o network.o synapse.o dataAnalysis.o

Resulting in:

neuron.o: In function `neuron::updateSpikeTime()':
/home/kaare/LIFnetworks/neuron.cpp:123: undefined reference to `gsl_root_fsolver_set'
/home/kaare/LIFnetworks/neuron.cpp:131: undefined reference to `gsl_root_fsolver_iterate'
/home/kaare/LIFnetworks/neuron.cpp:132: undefined reference to `gsl_root_fsolver_root'
/home/kaare/LIFnetworks/neuron.cpp:133: undefined reference to `gsl_root_fsolver_x_lower'
/home/kaare/LIFnetworks/neuron.cpp:134: undefined reference to `gsl_root_fsolver_x_upper'
/home/kaare/LIFnetworks/neuron.cpp:135: undefined reference to `gsl_root_test_interval'
/home/kaare/LIFnetworks/neuron.cpp:140: undefined reference to `gsl_root_fdfsolver_set'
/home/kaare/LIFnetworks/neuron.cpp:147: undefined reference to `gsl_root_fdfsolver_iterate'
/home/kaare/LIFnetworks/neuron.cpp:149: undefined reference to `gsl_root_fdfsolver_root'
/home/kaare/LIFnetworks/neuron.cpp:150: undefined reference to `gsl_root_test_delta'
neuron.o: In function `__static_initialization_and_destruction_0':
/home/kaare/LIFnetworks/neuron.cpp:16: undefined reference to `gsl_root_fsolver_brent'
/home/kaare/LIFnetworks/neuron.cpp:17: undefined reference to `gsl_root_fsolver_alloc'
/home/kaare/LIFnetworks/neuron.cpp:19: undefined reference to `gsl_root_fdfsolver_newton'
/home/kaare/LIFnetworks/neuron.cpp:20: undefined reference to `gsl_root_fdfsolver_alloc'
collect2: ld returned 1 exit status
make: *** [main] Error 1

So, I assume that I am not linking to the binary correctly? According to http://www.gnu.org/s/gsl/manual/html_node/Linking-programs-with-the-library.html, I have to link to the location of libgsl.a. However, looking in the folder:

kaare@kaare-Inspiron-1720:/usr/lib$ ls libgsl*
libgsl.a       libgslcblas.so    libgslcblas.so.0.0.0  libgsl.so.0
libgslcblas.a  libgslcblas.so.0  libgsl.so             libgsl.so.0.16.0

Any ideas to what I'm doing wrong? I have had some difficulties figuring out which package to install, as there seems to not be just one gsl-package out there. I have no recollection of what I did last time.

So, the problem is getting weirder (or more specific, at any rate). I tried compiling the example from http://www.gnu.org/s/gsl/manual/html_node/Root-Finding-Examples.html, and that works just fine.

Piling their example into a test.cpp file, and running

g++ -o test test.o  -Wall -g -lgsl -lgslcblas -lm   -I /usr/include/gsl

I get a fully functional program.
So, g++ now has no difficulty finding the exact same functions that it can't find in the other case, despite the linking information being the same. Does anyone have any idea what might create this kind of behavior? I am afraid I don't yet have a minimal example, as the code-bit is hidden deep inside a large program that worked yesterday.
I am using the same header files as the working example is.

Input is, as always, much appreciated =)

So, I believe I now have something close to a minimal example.

In both cases, let test.cpp be:

#include "dummy.h"

   
   int main()
   {
	   dummy object;
	   object.test();
   }

In case 1, let dummy.h:

#include <gsl/gsl_roots.h>


class dummy{

private:

public:

void test();

};

void dummy::test(){
       
   const gsl_root_fsolver_type *T;
 
   T = gsl_root_fsolver_brent;

}

Compiling this:

make test
g++ -Wall -g -lgsl -lgslcblas -lm   -I /usr/include/gsl   -c -o test.o test.cpp
In file included from test.cpp:4:0:
dummy.h: In member function ‘void dummy::test()’:
dummy.h:16:33: warning: variable ‘T’ set but not used [-Wunused-but-set-variable]
g++ -o test test.o  -Wall -g -lgsl -lgslcblas -lm   -I /usr/include/gsl

So no undefined references.

In case 2:
I move the function definition to a source file, and link the object-version of that instead of including everything:

dummy.h:

#include <gsl/gsl_roots.h>


class dummy{

private:

public:

void test();

};

dummy.cpp:

#include "dummy.h"

void dummy::test(){
       
   const gsl_root_fsolver_type *T;
 
   T = gsl_root_fsolver_brent;

}

same code, it's just copy-pasted.

I compile this

make test
g++ -Wall -g -lgsl -lgslcblas -lm   -I /usr/include/gsl   -c -o test.o test.cpp
g++ -o dummy.o -c dummy.cpp -Wall -g -lgsl -lgslcblas -lm   -I /usr/include/gsl 
dummy.cpp: In member function ‘void dummy::test()’:
dummy.cpp:7:33: warning: variable ‘T’ set but not used [-Wunused-but-set-variable]
g++ -o test test.o  -Wall -g -lgsl -lgslcblas -lm   -I /usr/include/gsl dummy.o
dummy.o: In function `dummy::test()':
/home/kaare/LIFnetworks/makingSense/dummy.cpp:9: undefined reference to `gsl_root_fsolver_brent'
collect2: ld returned 1 exit status
make: *** [test] Error 1

so, g++ can't find the gsl binaries when I compile it in steps?

So, I found it myself. I hope my blunder will be instructive to others:

The binary libraries have to be added at the very end of the call. So putting
-lgsl -lgslcblas -lm AFTER dummy.o removed the problem.

I was certain that I tested for that fix yesterday, but apparently I didn't, or the repeated installations of GSL and g++ during yesterday fixed the problem without me noticing. This also fixes the original problem.

I have on idea why this Makefile didn't cause any problems before the reinstall of linux.

Hi there,
many thanks for your post. I had the same problem; compiling fine with -lgsl -lgslcblas put before the -o on ubuntu 10.10 64bits, but failed on 11.10 64bits. Moving the options to the end of the command line did the trick.
Cheers
Thibaut

Thibaut, thank you very much! Putting "-lgsl -lgslcblas -lm " after "-o" worked for me too!