Problems with linking GSL / CBLAS

EDIT: Problem resolved, see my answer below.

Is there a problem with the GSL library in Oneiric? I'm having trouble linking and don't understand why -- this works fine in 10.4, 10.10, and 11.4.

EDIT: small test cases first, full problem is below:

Works fine on Natty:

$ cat /etc/issue
Ubuntu 11.04 \n \l

$ cat gsl-test.cpp
#include <gsl/gsl_errno.h>
void handler(const char *, const char *, int, int) { }
int main() { gsl_set_error_handler(handler); }

$ g++ gsl-test.cpp  ## Expect problems since libraries not linked in
/tmp/ccnjUNdv.o: In function `main':
gsl-test.cpp:(.text+0x16): undefined reference to `gsl_set_error_handler'
collect2: ld returned 1 exit status

$ g++ -lgsl -lgslcblas gsl-test.cpp
$ ./a.out
$

Fails on Oneiric:

$ cat /etc/issue
Ubuntu 11.10 \n \l

$ cat gsl-test.cpp
#include <gsl/gsl_errno.h>
void handler(const char *, const char *, int, int) { }
int main() { gsl_set_error_handler(handler); }

$ g++ gsl-test.cpp
/tmp/ccWKJMov.o: In function `main':
gsl-test.cpp:(.text+0x16): undefined reference to `gsl_set_error_handler'
collect2: ld returned 1 exit status

$ g++ -lgsl -lgslcblas -lm gsl-test.cpp
/tmp/ccV0UIx5.o: In function `main':
gsl-test.cpp:(.text+0x16): undefined reference to `gsl_set_error_handler'
collect2: ld returned 1 exit status

But this works on Oneiric:

$ g++ gsl-test.cpp -lgsl -lgslcblas
$ ./a.out

I suspect there's some difference in how g++ is working (4.6.1 vs. 4.5.2).

EDIT:

$ nm /usr/lib/libgslcblas.so
nm: /usr/lib/libgslcblas.so: no symbols
$ nm /usr/lib/libgslcblas.a|grep 'cblas_zher2k\|cblas_dtrsm\|cblas_zhemm'
00000000 T cblas_dtrsm
00000000 T cblas_zhemm
00000000 T cblas_zher2k

And here's the full problem, which seems to have a bit of a different flavor than my test case above, since it still isn't fixed by putting -lgsl -lgslcblas at the end of the line:

/usr/bin/c++   -g -O2  -O2 -g   -Wl,-Bsymbolic-functions CMakeFiles/css.dir/main.cpp.o  -o ../../../bin/css -rdynamic ../../../lib/libtemt.so.5.2.3 -lCoin -lQuarter -lQtOpenGL -lQtWebKit -lQtGui -lQtXml -lQtXmlPatterns -lQtNetwork -lQtCore -lode -lgslcblas -lgsl -lGLU -lGL -lSM -lICE -lX11 -lXext -lz -lreadline -lreadline -ltermcap -Wl,-rpath,/tmp/emergent-5.2.3/build/lib: 
/usr/lib/gcc/i686-linux-gnu/4.6.1/../../../../lib/libgsl.so: undefined reference to `cblas_zher2k'
/usr/lib/gcc/i686-linux-gnu/4.6.1/../../../../lib/libgsl.so: undefined reference to `cblas_dtrsm'
/usr/lib/gcc/i686-linux-gnu/4.6.1/../../../../lib/libgsl.so: undefined reference to `cblas_zhemm'
/usr/lib/gcc/i686-linux-gnu/4.6.1/../../../../lib/libgsl.so: undefined reference to `cblas_sgemv'
/usr/lib/gcc/i686-linux-gnu/4.6.1/../../../../lib/libgsl.so: undefined reference to `cblas_dgemm'
/usr/lib/gcc/i686-linux-gnu/4.6.1/../../../../lib/libgsl.so: undefined reference to `cblas_drotg'
/usr/lib/gcc/i686-linux-gnu/4.6.1/../../../../lib/libgsl.so: undefined reference to `cblas_sscal'
/usr/lib/gcc/i686-linux-gnu/4.6.1/../../../../lib/libgsl.so: undefined reference to `cblas_cdotc_sub'
/usr/lib/gcc/i686-linux-gnu/4.6.1/../../../../lib/libgsl.so: undefined reference to `cblas_ssymm'
/usr/lib/gcc/i686-linux-gnu/4.6.1/../../../../lib/libgsl.so: undefined reference to `cblas_zherk'
/usr/lib/gcc/i686-linux-gnu/4.6.1/../../../../lib/libgsl.so: undefined reference to `cblas_caxpy'
/usr/lib/gcc/i686-linux-gnu/4.6.1/../../../../lib/libgsl.so: undefined reference to `cblas_scasum'
/usr/lib/gcc/i686-linux-gnu/4.6.1/../../../../lib/libgsl.so: undefined reference to `cblas_dgemv'
/usr/lib/gcc/i686-linux-gnu/4.6.1/../../../../lib/libgsl.so: undefined reference to `cblas_cgemm'
/usr/lib/gcc/i686-linux-gnu/4.6.1/../../../../lib/libgsl.so: undefined reference to `cblas_isamax'
/usr/lib/gcc/i686-linux-gnu/4.6.1/../../../../lib/libgsl.so: undefined reference to `cblas_dtrsv'
/usr/lib/gcc/i686-linux-gnu/4.6.1/../../../../lib/libgsl.so: undefined reference to `cblas_sswap'
/usr/lib/gcc/i686-linux-gnu/4.6.1/../../../../lib/libgsl.so: undefined reference to `cblas_cher2'
/usr/lib/gcc/i686-linux-gnu/4.6.1/../../../../lib/libgsl.so: undefined reference to `cblas_dasum'
/usr/lib/gcc/i686-linux-gnu/4.6.1/../../../../lib/libgsl.so: undefined reference to `cblas_cgeru'
/usr/lib/gcc/i686-linux-gnu/4.6.1/../../../../lib/libgsl.so: undefined reference to `cblas_csscal'
/usr/lib/gcc/i686-linux-gnu/4.6.1/../../../../lib/libgsl.so: undefined reference to `cblas_chemm'
/usr/lib/gcc/i686-linux-gnu/4.6.1/../../../../lib/libgsl.so: undefined reference to `cblas_ctrsv'
/usr/lib/gcc/i686-linux-gnu/4.6.1/../../../../lib/libgsl.so: undefined reference to `cblas_icamax'
/usr/lib/gcc/i686-linux-gnu/4.6.1/../../../../lib/libgsl.so: undefined reference to `cblas_scnrm2'
/usr/lib/gcc/i686-linux-gnu/4.6.1/../../../../lib/libgsl.so: undefined reference to `cblas_ctrsm'
/usr/lib/gcc/i686-linux-gnu/4.6.1/../../../../lib/libgsl.so: undefined reference to `cblas_drotmg'
/usr/lib/gcc/i686-linux-gnu/4.6.1/../../../../lib/libgsl.so: undefined reference to `cblas_dsyrk'
/usr/lib/gcc/i686-linux-gnu/4.6.1/../../../../lib/libgsl.so: undefined reference to `cblas_dznrm2'
/usr/lib/gcc/i686-linux-gnu/4.6.1/../../../../lib/libgsl.so: undefined reference to `cblas_ssyr2k'
/usr/lib/gcc/i686-linux-gnu/4.6.1/../../../../lib/libgsl.so: undefined reference to `cblas_chemv'
/usr/lib/gcc/i686-linux-gnu/4.6.1/../../../../lib/libgsl.so: undefined reference to `cblas_dsyr2'
/usr/lib/gcc/i686-linux-gnu/4.6.1/../../../../lib/libgsl.so: undefined reference to `cblas_srotm'
/usr/lib/gcc/i686-linux-gnu/4.6.1/../../../../lib/libgsl.so: undefined reference to `cblas_dscal'
/usr/lib/gcc/i686-linux-gnu/4.6.1/../../../../lib/libgsl.so: undefined reference to `cblas_cdotu_sub'
/usr/lib/gcc/i686-linux-gnu/4.6.1/../../../../lib/libgsl.so: undefined reference to `cblas_zswap'
/usr/lib/gcc/i686-linux-gnu/4.6.1/../../../../lib/libgsl.so: undefined reference to `cblas_dswap'
/usr/lib/gcc/i686-linux-gnu/4.6.1/../../../../lib/libgsl.so: undefined reference to `cblas_zcopy'
/usr/lib/gcc/i686-linux-gnu/4.6.1/../../../../lib/libgsl.so: undefined reference to `cblas_ztrmv'
/usr/lib/gcc/i686-linux-gnu/4.6.1/../../../../lib/libgsl.so: undefined reference to `cblas_scopy'
/usr/lib/gcc/i686-linux-gnu/4.6.1/../../../../lib/libgsl.so: undefined reference to `cblas_drot'
/usr/lib/gcc/i686-linux-gnu/4.6.1/../../../../lib/libgsl.so: undefined reference to `cblas_ssyrk'
/usr/lib/gcc/i686-linux-gnu/4.6.1/../../../../lib/libgsl.so: undefined reference to `cblas_zsyr2k'
/usr/lib/gcc/i686-linux-gnu/4.6.1/../../../../lib/libgsl.so: undefined reference to `cblas_zaxpy'
/usr/lib/gcc/i686-linux-gnu/4.6.1/../../../../lib/libgsl.so: undefined reference to `cblas_zher'
/usr/lib/gcc/i686-linux-gnu/4.6.1/../../../../lib/libgsl.so: undefined reference to `cblas_daxpy'
/usr/lib/gcc/i686-linux-gnu/4.6.1/../../../../lib/libgsl.so: undefined reference to `cblas_cscal'
/usr/lib/gcc/i686-linux-gnu/4.6.1/../../../../lib/libgsl.so: undefined reference to `cblas_srotmg'
/usr/lib/gcc/i686-linux-gnu/4.6.1/../../../../lib/libgsl.so: undefined reference to `cblas_ssyr'
/usr/lib/gcc/i686-linux-gnu/4.6.1/../../../../lib/libgsl.so: undefined reference to `cblas_strsm'
/usr/lib/gcc/i686-linux-gnu/4.6.1/../../../../lib/libgsl.so: undefined reference to `cblas_dsymv'
/usr/lib/gcc/i686-linux-gnu/4.6.1/../../../../lib/libgsl.so: undefined reference to `cblas_zgeru'
/usr/lib/gcc/i686-linux-gnu/4.6.1/../../../../lib/libgsl.so: undefined reference to `cblas_dcopy'
/usr/lib/gcc/i686-linux-gnu/4.6.1/../../../../lib/libgsl.so: undefined reference to `cblas_snrm2'
/usr/lib/gcc/i686-linux-gnu/4.6.1/../../../../lib/libgsl.so: undefined reference to `cblas_dtrmm'
/usr/lib/gcc/i686-linux-gnu/4.6.1/../../../../lib/libgsl.so: undefined reference to `cblas_strsv'
/usr/lib/gcc/i686-linux-gnu/4.6.1/../../../../lib/libgsl.so: undefined reference to `cblas_zdotc_sub'
/usr/lib/gcc/i686-linux-gnu/4.6.1/../../../../lib/libgsl.so: undefined reference to `cblas_strmm'
/usr/lib/gcc/i686-linux-gnu/4.6.1/../../../../lib/libgsl.so: undefined reference to `cblas_csymm'
/usr/lib/gcc/i686-linux-gnu/4.6.1/../../../../lib/libgsl.so: undefined reference to `cblas_sger'
/usr/lib/gcc/i686-linux-gnu/4.6.1/../../../../lib/libgsl.so: undefined reference to `cblas_zscal'
/usr/lib/gcc/i686-linux-gnu/4.6.1/../../../../lib/libgsl.so: undefined reference to `cblas_srotg'
/usr/lib/gcc/i686-linux-gnu/4.6.1/../../../../lib/libgsl.so: undefined reference to `cblas_strmv'
/usr/lib/gcc/i686-linux-gnu/4.6.1/../../../../lib/libgsl.so: undefined reference to `cblas_cgerc'
/usr/lib/gcc/i686-linux-gnu/4.6.1/../../../../lib/libgsl.so: undefined reference to `cblas_saxpy'
/usr/lib/gcc/i686-linux-gnu/4.6.1/../../../../lib/libgsl.so: undefined reference to `cblas_cherk'
/usr/lib/gcc/i686-linux-gnu/4.6.1/../../../../lib/libgsl.so: undefined reference to `cblas_dsdot'
/usr/lib/gcc/i686-linux-gnu/4.6.1/../../../../lib/libgsl.so: undefined reference to `cblas_ssymv'
/usr/lib/gcc/i686-linux-gnu/4.6.1/../../../../lib/libgsl.so: undefined reference to `cblas_zher2'
/usr/lib/gcc/i686-linux-gnu/4.6.1/../../../../lib/libgsl.so: undefined reference to `cblas_ddot'
/usr/lib/gcc/i686-linux-gnu/4.6.1/../../../../lib/libgsl.so: undefined reference to `cblas_dnrm2'
/usr/lib/gcc/i686-linux-gnu/4.6.1/../../../../lib/libgsl.so: undefined reference to `cblas_cgemv'
/usr/lib/gcc/i686-linux-gnu/4.6.1/../../../../lib/libgsl.so: undefined reference to `cblas_zgemv'
/usr/lib/gcc/i686-linux-gnu/4.6.1/../../../../lib/libgsl.so: undefined reference to `cblas_ctrmv'
/usr/lib/gcc/i686-linux-gnu/4.6.1/../../../../lib/libgsl.so: undefined reference to `cblas_cswap'
/usr/lib/gcc/i686-linux-gnu/4.6.1/../../../../lib/libgsl.so: undefined reference to `cblas_zgemm'
/usr/lib/gcc/i686-linux-gnu/4.6.1/../../../../lib/libgsl.so: undefined reference to `cblas_ctrmm'
/usr/lib/gcc/i686-linux-gnu/4.6.1/../../../../lib/libgsl.so: undefined reference to `cblas_csyrk'
/usr/lib/gcc/i686-linux-gnu/4.6.1/../../../../lib/libgsl.so: undefined reference to `cblas_dsyr2k'
/usr/lib/gcc/i686-linux-gnu/4.6.1/../../../../lib/libgsl.so: undefined reference to `cblas_dsyr'
/usr/lib/gcc/i686-linux-gnu/4.6.1/../../../../lib/libgsl.so: undefined reference to `cblas_sgemm'
/usr/lib/gcc/i686-linux-gnu/4.6.1/../../../../lib/libgsl.so: undefined reference to `cblas_srot'
/usr/lib/gcc/i686-linux-gnu/4.6.1/../../../../lib/libgsl.so: undefined reference to `cblas_dzasum'
/usr/lib/gcc/i686-linux-gnu/4.6.1/../../../../lib/libgsl.so: undefined reference to `cblas_idamax'
/usr/lib/gcc/i686-linux-gnu/4.6.1/../../../../lib/libgsl.so: undefined reference to `cblas_csyr2k'
/usr/lib/gcc/i686-linux-gnu/4.6.1/../../../../lib/libgsl.so: undefined reference to `cblas_zhemv'
/usr/lib/gcc/i686-linux-gnu/4.6.1/../../../../lib/libgsl.so: undefined reference to `cblas_drotm'
/usr/lib/gcc/i686-linux-gnu/4.6.1/../../../../lib/libgsl.so: undefined reference to `cblas_dsymm'
/usr/lib/gcc/i686-linux-gnu/4.6.1/../../../../lib/libgsl.so: undefined reference to `cblas_zsyrk'
/usr/lib/gcc/i686-linux-gnu/4.6.1/../../../../lib/libgsl.so: undefined reference to `cblas_sdsdot'
/usr/lib/gcc/i686-linux-gnu/4.6.1/../../../../lib/libgsl.so: undefined reference to `cblas_zgerc'
/usr/lib/gcc/i686-linux-gnu/4.6.1/../../../../lib/libgsl.so: undefined reference to `cblas_ssyr2'
/usr/lib/gcc/i686-linux-gnu/4.6.1/../../../../lib/libgsl.so: undefined reference to `cblas_cher'
/usr/lib/gcc/i686-linux-gnu/4.6.1/../../../../lib/libgsl.so: undefined reference to `cblas_zsymm'
/usr/lib/gcc/i686-linux-gnu/4.6.1/../../../../lib/libgsl.so: undefined reference to `cblas_ztrsm'
/usr/lib/gcc/i686-linux-gnu/4.6.1/../../../../lib/libgsl.so: undefined reference to `cblas_cher2k'
/usr/lib/gcc/i686-linux-gnu/4.6.1/../../../../lib/libgsl.so: undefined reference to `cblas_sasum'
/usr/lib/gcc/i686-linux-gnu/4.6.1/../../../../lib/libgsl.so: undefined reference to `cblas_ztrsv'
/usr/lib/gcc/i686-linux-gnu/4.6.1/../../../../lib/libgsl.so: undefined reference to `cblas_ccopy'
/usr/lib/gcc/i686-linux-gnu/4.6.1/../../../../lib/libgsl.so: undefined reference to `cblas_ztrmm'
/usr/lib/gcc/i686-linux-gnu/4.6.1/../../../../lib/libgsl.so: undefined reference to `cblas_dger'
/usr/lib/gcc/i686-linux-gnu/4.6.1/../../../../lib/libgsl.so: undefined reference to `cblas_dtrmv'
/usr/lib/gcc/i686-linux-gnu/4.6.1/../../../../lib/libgsl.so: undefined reference to `cblas_izamax'
/usr/lib/gcc/i686-linux-gnu/4.6.1/../../../../lib/libgsl.so: undefined reference to `cblas_zdscal'
/usr/lib/gcc/i686-linux-gnu/4.6.1/../../../../lib/libgsl.so: undefined reference to `cblas_sdot'
/usr/lib/gcc/i686-linux-gnu/4.6.1/../../../../lib/libgsl.so: undefined reference to `cblas_zdotu_sub'
collect2: ld returned 1 exit status

I get the same slew of undefined references if I do this, whether on Natty or Oneiric:

$ g++ gsl-test.cpp -lgsl

Not sure what to make of that yet.


Try to write -lgsl before -lgslcblas. I know that's stupid, but for me it works...


The problem was that libtemt.so.5.2.3 was also linked against the GSL libraries, and in the wrong order. Somehow that link succeeded, but caused the next one to fail. Once I linked libtemt with the ordering: -lgsl -lgslcblas, then I could link the css executable with the same correct ordering, and it succeeded. Now I just need to figure out how to convince CMake to write the correct link.txt file.