图书馆链接在linux中

时间:2015-09-07 19:30:14

标签: c++ linux libraries

我是这个领域的新手。 我正在安装一个在运行时链接到另一个库(gsl)的库,如下所示:

g++ x.cpp y.cpp z.cpp -o abc -lgsl -lm -lgslcblas

我目前正在使用服务器,因此没有root权限。

gsl是一个依赖项,因此我做了gsl的本地安装。以下是我遵循的步骤:

1) Downloaded the gsl-latest.tar.gz
2) tar -zxvf gsl-latest.tar.gz
3) From inside the gsl-1.16 (latest) folder I did:
   a) ./configure --prefix=local-folder-path
   b) make
   c) make check
   d) make install
   Everything is successfully completed.

现在,由于主库将其链接为运行时,我在LD_LIBRARY_PATH中设置了此bin的路径。

export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/a/b/c/gsl-1.16-bin/bin/

现在,当我转到主库的文件夹并执行'make'时,它仍然会给我以下错误,例如:

error: gsl/gsl_vector.h: No such file or directory
error: ‘gsl_vector_get’ was not declared in this scope
error: ‘gsl_vector_set’ was not declared in this scope
error: ‘gsl_vector_get’ was not declared in this scope
error: ‘gsl_vector_set’ was not declared in this scope
error: ‘gsl_vector_memcpy’ was not declared in this scope
At global scope:
error: ISO C++ forbids declaration of ‘gsl_vector’ with no type
error: expected ‘,’ or ‘...’ before ‘*’ token

我是否还需要在其他地方设置路径?

任何帮助将不胜感激。 谢谢

1 个答案:

答案 0 :(得分:0)

问题是include路径。您需要将-I添加到编译行以查找目录。

也可以指定RPATH Wikipedia RPATH来指定库的位置