简体   繁体   中英

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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