开发者

g++ linking issue with GSL

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


I had to do this regularly, do as following :

  • On the server, create one directory in your home directory to install the library (let's say mypref) and another one to build the library (let's say tmp). You have two new directories : ~/mypref and ~/tmp.
  • Download GSL sources in ~/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

  • Launch the configure script specifying ~/mypref as the installation prefix (and maybe other options depending of your server) :

./configure --prefix=${HOME}/mypref

  • Make :

make

  • And install :

make install

  • Now you can remove safely the ~/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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜