g++与 GSL 的链接问题
g++ -o program main.cpp classOne.cpp classTwo.cpp -lgsl -lgslblas -lm
这就是我在安装 GSL 软件包时进行编译的方式。 但现在我正在一台无权安装 GSL-Library 的服务器上工作。 我有什么选择?
谢谢
g++ -o program main.cpp classOne.cpp classTwo.cpp -lgsl -lgslblas -lm
that's how i compile when the GSL-packages are installed.
but now I'm working on a server where i don't have rights to install GSL-Library.
What are my options?
thx
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我必须定期执行此操作,请执行以下操作:
mypref
),并创建另一个目录来构建库(假设为>tmp
)。您有两个新目录:~/mypref
和~/tmp
。~/tmp
中的 GSL 源代码(最新版本为 ftp://ftp.gnu.org/gnu/gsl/gsl-1.14.tar.gz),解压并进入生成的子目录(gsl-1.14
):cd ~/tmp
wget ftp://ftp.gnu.org/gnu/gsl/gsl-1.14.tar.gz
tar -xvzf gsl-1.14.tar.gz
cd gsl-1.14
configure
脚本,指定~/mypref
作为安装前缀(可能还有其他选项,具体取决于您的服务器):./configure --prefix=${HOME}/mypref
make
make install
~ /tmp
目录:cd; rm -rf tmp
现在您可以使用以下命令编译程序:
g++ -o program main.cpp classOne.cpp classTwo.cpp -I${HOME}/mypref/include -lm -L${HOME} /mypref/lib -lgsl -lgslcblas
-I
和-L
分别表示标头和库的路径。如果您的程序要在主目录不可见的上下文中执行,请考虑静态链接:g++ -o program main.cpp classOne.cpp classTwo.cpp ${HOME}/mypref/lib/libgsl。 a ${HOME}/mypref/lib/libgslcblas.a -I${HOME}/mypref/include -lm
最后一个命令生成的二进制文件比以前更大,但完全独立于 GSL 和 GSLCBLAS。
I had to do this regularly, do as following :
mypref
) and another one to build the library (let's saytmp
). You have two new directories :~/mypref
and~/tmp
.~/tmp
(last version is ftp://ftp.gnu.org/gnu/gsl/gsl-1.14.tar.gz), extract and go in the generated sub-directory (gsl-1.14
) :cd ~/tmp
wget ftp://ftp.gnu.org/gnu/gsl/gsl-1.14.tar.gz
tar -xvzf gsl-1.14.tar.gz
cd gsl-1.14
configure
script specifying~/mypref
as the installation prefix (and maybe other options depending of your server) :./configure --prefix=${HOME}/mypref
make
make install
~/tmp
directory :cd; rm -rf tmp
Now you can compile your program using :
g++ -o program main.cpp classOne.cpp classTwo.cpp -I${HOME}/mypref/include -lm -L${HOME}/mypref/lib -lgsl -lgslcblas
-I
and-L
indicate respectively the path for the headers and the library. If your program is meant to be executed in a context where your home directory is not visible, consider static linking :g++ -o program main.cpp classOne.cpp classTwo.cpp ${HOME}/mypref/lib/libgsl.a ${HOME}/mypref/lib/libgslcblas.a -I${HOME}/mypref/include -lm
The binary produced by the last command is bigger than previously, but entirely independent from GSL and GSLCBLAS.