如何从/usr/local/include/以外的文件夹安装和调用c++库



我已经git克隆了包https://github.com/alex-mcdaniel/RX-DMFIT到计算集群目录。

它需要GNU计算库,我从https://www.gnu.org/software/gsl/。

问题是make install提供了cannot create directory '/usr/local/include/gsl': Permission denied,因为我在集群上没有管理员权限,所以我想将gsl库安装在我有权限的文件夹中,并告诉RX-DMFIT包在哪里查找。

RX-DMFIT的生成文件是

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)

如何做到这一点,需要对makefile进行哪些修改?

这个问题包含两个部分:如何将Gsl安装到自定义目录,以及如何修改RX-DMFIT的Makefile以从自定义目录使用Gsl。

将Gsl安装到自定义前缀

要将Gsl安装到自定义目录中,请在运行makemake 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

使用来自自定义前缀的Gsl

要从自定义前缀使用Gsl,请将-I/path/to/custom/prefix/include-L/path/to/custom/prefix/lib添加到传递给编译器的命令行参数中。-I标志告诉编译器在自定义前缀下搜索头文件,-L标志告诉编译器在链接程序时搜索(共享(库。

在Makefile中有很多方法可以做到这一点,下面是其中之一:

# 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 

最新更新