链接 GSL / CBLAS 的问题

链接 GSL / CBLAS 的问题

编辑:问题已解决,请参阅下面的回答。

Oneiric 中的 GSL 库有问题吗?我在链接时遇到了麻烦,但不明白为什么——它在 10.4、10.10 和 11.4 中运行良好。

编辑:首先进行小测试用例,完整问题如下:

在 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
$

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

但这在 Oneiric 上有效:

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

我怀疑 g++ 的工作方式存在一些差异(4.6.1 与 4.5.2)。

编辑

$ 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

这是完整的问题,它似乎与我上面的测试用例有点不同,因为它仍然没有通过在行-lgsl -lgslcblas末添加以下内容来修复:

/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

如果我这样做,无论是在 Natty 还是 Oneiric 上,我都会得到同样多的未定义的引用:

$ g++ gsl-test.cpp -lgsl

目前还不确定该如何理解。

答案1

尝试-lgsl先写-lgslcblas。我知道这很蠢,但对我来说这很有效...

答案2

问题是libtemt.so.5.2.3也链接到了 GSL 库,而且顺序错误。不知何故,那个链接成功了,但导致下一个链接失败。一旦我使用libtemtordering:进行链接-lgsl -lgslcblas,我就可以css以相同的正确顺序链接可执行文件,并且成功了。现在我只需要弄清楚如何说服 CMake 编写正确的link.txt文件。

相关内容