简体   繁体   English

链接到集群上的GNU科学图书馆?

[英]Linking to GNU scientific library on cluster?

I am running a code ( iHARM2D ) which requires the GNU scientific library library (GSL) on a cluster. 我正在运行一个代码( iHARM2D ),该代码需要群集上的GNU科学库库 (GSL)。 Since the GSL library is not installed on the cluster, I have to compile it there and properly link it during compilation of the actual code. 由于GSL库未安装在集群上,因此我必须在该库中进行编译并在编译实际代码期间正确链接它。 In my shell script I write 在我的shell脚本中,我写

cd whereGSLsource
./configure --prefix=/homefolder/iHARM/GSLcompiled
make && make install

This compiles the GSL and puts the results in /homefolder/iHARM/GSLcompiled/lib, /homefolder/iHARM/GSLcompiled/include etc. 这将编译GSL,并将结果放入/ homefolder / iHARM / GSLcompiled / lib,/ homefolder / iHARM / GSLcompiled / include等。

According to this answer , I should be able to compile by writing the following lines into my shell script before compilation of my main code 根据这个答案 ,我应该能够在编译我的主代码之前,将以下几行写到我的shell脚本中进行编译

export CPATH="/homefolder/iHARM/GSLcompiled/include":$CPATH
export LIBRARY_PATH="/homefolder/iHARM/GSLcompiled/lib":$LIBRARY_PATH

However, this does not seem to link GSL properly because the compilation returns errors of the type "undefined reference to `gsl_some_function'". 但是,这似乎无法正确链接GSL,因为编译返回的错误类型为“未定义对gsl_some_function的引用”。 (It works on my computer when default installation and linking of GSL is used.) (当使用默认安装和GSL链接时,它可以在我的计算机上使用。)

Another possibility suggested by the GSL output during compilation or this answer is to modify the LD_LIBRARY_PATH variable GSL输出在编译或此答案期间建议的另一种可能性是修改LD_LIBRARY_PATH变量

LD_LIBRARY_PATH="/homefolder/iHARM/GSLcompiled/lib":$LD_LIBRARY_PATH

But this gives the same result. 但这给出了相同的结果。 Similarly it does not when I try to link using the -L and -I option 同样,当我尝试使用-L和-I选项进行链接时,它不会

cd iHARM
gcc -someoptions -I../GSLcompiled/include/ -L../GSLcompiled/lib ./some.o -o harm

Another option suggested by GSL was to use GSL建议的另一个选择是使用

gcc -someoptions -Wl,-rpath -Wl,"/homefolder/iHARM/GSLcompiled/lib" ./some.o -o harm

However, neither of these work. 但是,这些都不起作用。

How do I link the GSL properly then? 那如何正确链接GSL?

(I am not very experienced in this so this might also be some really basic mistake in the syntax or so.) (我对此并不十分有经验,因此这也可能是语法方面的一些基本错误。)

Run first configure --help ; 首先运行configure --help ; you'll find out that it accepts the --enable-static option which you do want to use. 您会发现它接受您要使用的--enable-static选项。

BTW you could (and probably should) install Linux on your laptop and compile on it (then scp a mostly statically linked binary to your cluster). 顺便说一句,您可以(可能应该)在笔记本电脑上安装Linux并在其上进行编译(然后将大部分静态链接的二进制文件scp链接到您的集群)。

You'll better share a common --prefix for all your autoconf-ed software. 您最好为所有自动配置的软件共享一个通用的--prefix See this . 看到这个 Read the documentation of autoconf . 阅读autoconf文档 Let's suppose you always use --prefix=$HOME/soft (which don't require any root permission). 假设您始终使用--prefix=$HOME/soft (不需要任何root权限)。

You could compile with make then do a make install DESTDIR=/tmp/gslinst so that installed things go into /tmp/gslinst which you would inspect and latter copy appropriately to a directory related to your prefix. 您可以使用make编译,然后进行make install DESTDIR=/tmp/gslinst以便将已安装的内容放入/tmp/gslinst进行检查,然后将其适当地复制到与前缀相关的目录中。

You'll find both libgsl.a and libgslcblas.a . 您将同时找到libgsl.alibgslcblas.a On my Debian system, the libgsl-dev package provides them (so I don't need to rebuild it). 在我的Debian系统上, libgsl-dev软件包提供了它们(所以我不需要重建它)。

Then you'll use these static libraries. 然后,您将使用这些静态库。 You could provide a full path for them, that is use $HOME/soft/lib/libgsl.a explicitly in your linking gcc command for harm , eg link it with 您可以为它们提供完整的路径,即在链接gcc命令中明确使用$HOME/soft/lib/libgsl.a进行harm ,例如,将其链接为

 gcc some.o $HOME/soft/lib/libgsl.a -o harm

but YMMV. 但是YMMV。 Order of arguments to gcc matters a lot. gcc的参数顺序很重要。

You don't need or want to mess with $LD_LIBRARY_PATH or -Wl,-rpath with static linking. 您不需要也不想弄乱带有静态链接的$LD_LIBRARY_PATH-Wl,-rpath Read about rpath when you want dynamic linking. 当您需要动态链接时,请阅读有关rpath的信息

See also what pkg-config tells. 另请参见pkg-config内容。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM