0

How can I set the library path for the current script that's running? I mean I don't want to list a new path for the libraries in a textfile. I tried it using export LD_LIBRARY_PATH=$(pwd)/lib/

This is the script:

#!/bin/bash
LD_LIBRARY_PATH="$(pwd)/lib/"
export LD_LIBRARY_PATH
./X3TC_config

closed as unclear what you're asking by Gilles, Michael Homer, Networker, Anthon, Braiam Apr 30 '15 at 22:26

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • Do you really mean $(pwd), or do you mean $(dirname $0)? – D_Bye Apr 30 '15 at 12:46
  • I mean $(pwd) . – nifker Apr 30 '15 at 13:23
  • 1
    The script you've posted does exactly what you're asking. If that's not working for you, tell us where the libraries are located, what the current directory is when you start the script, and copy-paste the error messages complaining of a missing library. I suspect that you're asking the wrong question but I can't tell what the right question would be with so little information. – Gilles Apr 30 '15 at 21:04
  • The libs are in the lib folder but it still says it cant find the "libgtk-x11-2.0.so.0" library – nifker May 1 '15 at 8:29
4

In your script, these two lines close to the top should do the trick:

LD_LIBRARY_PATH="$(pwd)/lib"
export LD_LIBRARY_PATH

Although bash allows you to set and export a variable in a single statement, not all shells do, so the two step approach is more portable, if that's a concern.

If this isn't working for you, check that you are running the script from the right place - using $(pwd) like this ties you to running the script from the directory that contains the required ./lib subdirectory.

If you want to be able to run the script from anywhere, you need to use the absolute path to the ./lib subdir, or construct a relative path from the directory portion of the path to the script using, e.g., $(dirname $0)

  • It still says it can't the required "libgtk-x11-2.0.so.0" although it is in the folder. – nifker Apr 30 '15 at 14:23
  • What is the command you are trying to call? Does it care about the value of LD_LIBRARY_PATH? – D_Bye Apr 30 '15 at 14:26
  • chmod +x testandlaunch ./testandlaunch – nifker Apr 30 '15 at 15:18
  • Is testandlaunch the program you are trying to set LD_LIBRARY_PATH for, or the script you are trying to modify to make that happen? It might help if you post the relevant parts of your script as an edit to your question. – D_Bye Apr 30 '15 at 16:52
  • It's the script. – nifker Apr 30 '15 at 17:04
1

you should execute you program in this way:

LD_LIBRARY_PATH=$(pwd)/lib/ <your_executable_here>
  • LD_LIBRARY_PATH=foo; export LD_LIBRARY_PATH is arguably slightly better - you only need it once in the script, and anything you call that cares about it will find it. No repetition, reduced scope for errors. You can override an existing setting with an inline assignment, if necessary. – D_Bye Apr 30 '15 at 12:57
  • 1
    @D_Bye, probably. But if you need this setting only for this script your way will mess other programs – Romeo Ninov Apr 30 '15 at 12:58
  • This doesn't change anything for the script that is running (which is what the OP asks for), only for a new invocation. – Anthon Apr 30 '15 at 13:18
  • Do you mean with <your_execition_here> a library? – nifker Apr 30 '15 at 13:25
  • No, by <your_executable_here> i mean the program you run. If its for example script, named testscript.sh the command will become: LD_LIBRARY_PATH=$(pwd)/lib/ testscript.sh – Romeo Ninov Apr 30 '15 at 13:27

Not the answer you're looking for? Browse other questions tagged or ask your own question.