【问题标题】:Adding a library file into a binary file将库文件添加到二进制文件中
【发布时间】:2016-07-27 08:37:20
【问题描述】:

我已经编译了源代码并在 LDFLAGS 中包含了适当的库文件。但是,当我想运行二进制文件时,它说缺少特定的 libX.a。如果我将库的路径添加到 LD_LIBRARY_PATH,一切都会好起来的。

有没有办法将该文件永久包含在二进制文件中以消除 LD_LIBRARY_PATH 步骤?

LDFLAGS=-L/export/apps/computer/scalapack -L/export/apps/computer/OpenBLAS-0.2.18
BLAS_LIBS=-lopenblas
SCALAPACK_LIBS=-lscalapack

COMP_LIBS=dc_lapack.a liblapack.a libblas.a
LIBS=$(SCALAPACK_LIBS) $(BLAS_LIBS) 

ldd 命令的输出,显示

# ./siesta
./siesta: error while loading shared libraries: libopenblas.so.0: cannot open shared object file: No such file or directory
# ldd siesta
    libopenblas.so.0 => not found
    ...

然而,

# ls ../../../computer/OpenBLAS-0.2.18/libopenblas* -l
lrwxrwxrwx 1 root root       33 Jul 27 11:58 ../../../computer/OpenBLAS-0.2.18/libopenblas.a -> libopenblas_piledriverp-r0.2.18.a
-rw-r--r-- 1 root root 28091912 Jul 27 11:59 ../../../computer/OpenBLAS-0.2.18/libopenblas_piledriverp-r0.2.18.a
-rwxr-xr-x 1 root root 14912094 Jul 27 12:00 ../../../computer/OpenBLAS-0.2.18/libopenblas_piledriverp-r0.2.18.so
lrwxrwxrwx 1 root root       34 Jul 27 12:00 ../../../computer/OpenBLAS-0.2.18/libopenblas.so -> libopenblas_piledriverp-r0.2.18.so
lrwxrwxrwx 1 root root       34 Jul 27 12:00 ../../../computer/OpenBLAS-0.2.18/libopenblas.so.0 -> libopenblas_piledriverp-r0.2.18.so

有什么想法吗?

【问题讨论】:

    标签: makefile shared-libraries ldd


    【解决方案1】:

    你有三种可能

    1. 静态链接午睡计划。

    或者我猜你正在寻找:

    1. 在路径中安装 OpenBLAS 库,该路径已经在您的 LD_LIBRARY_PATH 中,例如 /usr/local/lib

    2. 使用 -Wl,-R/path/to/OpenBLAS 编译器标志

    【讨论】:

    • 你能解释一下第一种方法吗
    • 在 Makefile 中将 -shared 替换为 -static 或代替 -lopenblas 将 openblas 静态库的完整路径写入目标文件列表
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-12-01
    • 2017-06-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多