c++ - Linux 中的库链接

标签 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

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

如有任何帮助,我们将不胜感激。 谢谢您

最佳答案

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

也可以指定 RPATH Wikipedia RPATH指定在哪里查找库

关于c++ - Linux 中的库链接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32445000/

相关文章:

c++ - 使用辅助数组的C++比较器排序

php - 禁用并发 Flash 视频流

C# 从 Windows 写入 ext2 linux 分区

linux - 为什么Linux命令中使用字符x表示提取?

c - 带有新库的 schoolproject 额外功能

c++ - 无法在matlab中的UDP客户端和linux中的服务器之间发送数据

c++ - 使用模板作为 std::map 中的键

c++ - OOP 图形用户界面,模板 C++

xcode - OpenFrameworks 的 Apple Mach-O 链接器 (Id) 错误

android - 可搜索微调器使我的应用程序在多任务处理时崩溃