Compile C++ code with gsl installed in user directory

GSL ( is a great C/C++ library for scientific computing. I always install a current copy of GSL in the server that I use. However, I don’t have admin access on those servers, and, as a result, I  cannot use ldconfig to add gsl library.  The following trick help me to compile my gsl C++ code.

1). Define environment variable $LD_LIBRARY_PATH (in BASH);

export LD_LIBRARY_PATH=$HOME/ext/lib

, where $HOME/ext/lib is where gsl library are installed and contains “” and other files.

2). Compile the C++ code and link them to gsl.

g++ gen_data.cpp -o gen_data -I/home/biobeatext/include -L /home/biobeat/ext/lib -lgsl -lgslcblas

3). Now ./gen_data will execute the code.

Without defining $LD_LIBRARY_PATH in Step 1, the following error message will be displayed when executing gen_data:

./gen_data: error while loading shared libraries: cannot open shared object file: No such file or directory

This is because the shell cannot find in ldconfig path, which can only be set by admin.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s