设置用于在运行时加载共享库的LD

编程入门 行业动态 更新时间:2024-10-26 16:32:49
本文介绍了设置用于在运行时加载共享库的LD_LIBRARY_PATH环境变量(g ++)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有两个相同问题的问题:

  • 我有一个共享对象保存在`pwd` / lib,而使用它的可执行文件成功编译(通过使用-l和-L开关),在运行时它给我的悲伤。如果我尝试运行 LD_LIBRARY_PATH = / my / absolute / path / to / library / directory ./test 它工作正常。但是如果我导出LD_LIBRARY_PATH = / my / absolute / path /到/ library /目录,并且执行 ./ test ,它表示它找不到共享库。但是,如果我执行 LD_LIBRARY_PATH = $ LD_LIBRARY_PATH ./test 再次它工作正常!关于我做错什么的任何想法?

  • 第二个问题与导出LD_LIBRARY_PATH env变量有关。如果我打开一个终端,输入导出LD_LIBRARY_PATH = / path / to / stuff 然后键入 echo $ LD_LIBRARY_PATH 变量是正确的。但是,如果我写一个包含导出命令的脚本,只需运行它就不会更新变量,而是需要运行 source install.sh ,以便实际保持变量。这是最好的解决方案?

  • 谢谢你的时间!

    解决方案

    首先回答第二个问题:

    source 执行当前shell中的脚本, ./ install.sh 打开并在不同的shell中执行。 http:/ /www.unix/unix-dummies-questions-answers/537-difference-between-source-exec-script.html

    现在为您的第一个问题:

    LD_LIBRARY_PATH = $ LD_LIBRARY_PATH ./test 在只有一个命令之前设置LD_LIBRARY_PATH变量( ./ test 命令)。由于上述相同的原因,我相信这没有被转移到任何shell ./ test 创建。要使其持续存在,您可能需要将导出LD_LIBRARY_PATH = ... 放在您的〜/ .bashrc / p>

    I'm having two problems related to the same issue:

  • I have a shared object saved in `pwd`/lib and while the executable that uses it compiles successfully (by using -l and -L switches), at runtime, it's giving me grief. If I try to run LD_LIBRARY_PATH=/my/absolute/path/to/library/directory ./test it works fine. But if I export LD_LIBRARY_PATH=/my/absolute/path/to/library/directory and do ./test it says that it can't find the shared library. However, if I do LD_LIBRARY_PATH=$LD_LIBRARY_PATH ./test again it works fine!! Any ideas on what I'm doing wrong?

  • Second issue is related to the exporting of the LD_LIBRARY_PATH env variable. If I open a terminal and type export LD_LIBRARY_PATH=/path/to/stuff and then type echo $LD_LIBRARY_PATH, the variable is correct. However if I write a script containing the export command, simply running it doesn't update the variable, instead I need to run source install.sh in order to actually persist the variable. What's the best solution for this?

  • Thank you for your time!

    解决方案

    To answer the second question first:

    source executes the script inside the current shell, ./install.sh opens and executes it in a different shell. www.unix/unix-dummies-questions-answers/537-difference-between-source-exec-script.html

    Now for your first question:

    LD_LIBRARY_PATH=$LD_LIBRARY_PATH ./test sets the LD_LIBRARY_PATH variable before just one command (the ./test command). For the same reason above, I believe this isn't getting transferred to whatever shell ./test creates. To make it persist, you may need to put the export LD_LIBRARY_PATH=... in your ~/.bashrc

    更多推荐

    设置用于在运行时加载共享库的LD

    本文发布于:2023-11-24 05:43:42,感谢您对本站的认可!
    本文链接:https://www.elefans.com/category/jswz/34/1624141.html
    版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
    本文标签:加载   LD

    发布评论

    评论列表 (有 0 条评论)
    草根站长

    >www.elefans.com

    编程频道|电子爱好者 - 技术资讯及电子产品介绍!