Home > Enterprise >  How to install and call c library from folder other than /usr/local/include/
How to install and call c library from folder other than /usr/local/include/

Time:10-31

I have git cloned the package https://github.com/alex-mcdaniel/RX-DMFIT to a computing cluster directory.

It requires the GNU computing library which I downloaded from https://www.gnu.org/software/gsl/ .

The issue is make install gives cannot create directory '/usr/local/include/gsl': Permission denied as I don't have admin privileges on the cluster, so I would like to instead install the gsl library in a folder which I have permissions for, and tell the RX-DMFIT package where to look.

The make file for RX-DMFIT is

FILES = Constants.cpp Target.cpp bfield.cpp DM_profile.cpp \
        greens.cpp diffusion.cpp dist.cpp psyn.cpp pIC.cpp \
        emissivity.cpp surface_brightness_profile.cpp      \
        flux.cpp calc_sv.cpp run.cpp


# prefix should point to location of darksusy
prefix = /global/scratch/projects/general/RX-DMFIT/darksusy-6.3.1

LDLIBS = -lgsl -lgslcblas -ldarksusy -lFH -lHB -lgfortran

example1: $(FILES) example1.cpp
    $(CXX) -o example1 $(FILES) example1.cpp  \
     -I/${prefix}/include -L/${prefix}/lib \
     $(LDLIBS)

example2: $(FILES) example2.cpp
    $(CXX) -o example2 $(FILES) example2.cpp  \
     -I/${prefix}/include -L/${prefix}/lib \
     $(LDLIBS)

How can I do this, and what modifications to the makefile are required?

CodePudding user response:

This question contains two parts: How to install Gsl to a custom directory, and also how to modify the Makefile of RX-DMFIT to use Gsl from the custom directory.

Install Gsl to a custom prefix

To install Gsl into a custom directory, configure it to use a custom prefix before running make and make install.

# Create a directory to be used as the custom prefix
mkdir -p /path/to/custom/prefix

# Configure gsl to use the custom prefix
./configure --prefix=/path/to/custom/prefix

# Build and install
make && make install

Use Gsl from the custom prefix

To use Gsl from the custom prefix, add -I/path/to/custom/prefix/include and -L/path/to/custom/prefix/lib to the command line arguments passed to the compiler. The -I flag tells the compiler to search for header files under the custom prefix, and the -L flag tells the compiler to search for (shared) libraries when linking the program.

There are many ways to do so in the Makefile, and here's one of them:

# Add this line under the "prefix = ..." line
gsl_prefix = /path/to/custom/prefix

# Add this line under every "-I/${prefix}/include -L/${prefix}/lib \" line
# Be sure to include the "\" at the end
-I${gsl_prefix}/include -L${gsl_prefix}/lib \
  • Related