Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 461 Vote(s) - 3.44 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Why do I have to define LD_LIBRARY_PATH with an export every time I run my application?

#1
I have some code that uses some shared libraries (c code on gcc). When compiling I have to explicitly define the include and library directories using -I and -L, since they aren't in the standard places. When I try to run the code, I get the following error:

./sync_test
./sync_test: error while loading shared libraries: libsync.so: cannot open shared object file: No such file or directory


However, do the following, everything works just fine:

export LD_LIBRARY_PATH="/path/to/library/"
./sync_test

Now, the strange part is, this only works once. If I try and run sync_test again I get the same error unless I run the export command first. I tried adding the following to my .bashrc, but it made no difference:

LD_LIBRARY_PATH="/path/to/library/"


Reply

#2
Did you 'export' in your .bashrc?

export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:"/path/to/library"
Reply

#3
You can just put this all on one line:

LD_LIBRARY_PATH="$LD_LIBRARY_PATH:/path/to/library" ./sync_test

Should make things a little easier, even if it doesn't change anything fundamental
Reply

#4
What you also can do, if it's something you installed on your system, is to add the directory that contains the shared libraries to your **/etc/ld.so.conf** file, or make a new file in **/etc/ld.so.conf.d/**

(I've both checked RHEL5 and Ubuntu distribution so I think it's generic for linux)

The ldconfig program will make sure they are system-wide included.

See the following link for more information:
[

[To see links please register here]

][1]


[1]:

[To see links please register here]

Reply

#5
Instead of overriding the library search path at runtime with LD_LIBRARY_PATH, you could instead bake it into the binary itself with `rpath`. If you link with GCC adding `-Wl,-rpath,<libdir>` should do the trick, if you link with ld it's just `-rpath <libdir>`.
Reply

#6
Use

export LD_LIBRARY_PATH="/path/to/library/"

in your .bashrc otherwise, it'll only be available to bash and not any programs you start.

Try `-R/path/to/library/` flag when you're linking, it'll make the program look in that directory and you won't need to set any environment variables.

EDIT: Looks like `-R` is Solaris only, and you're on Linux.

An alternate way would be to add the path to `/etc/ld.so.conf` and run `ldconfig`. Note that this is a global change that will apply to all dynamically linked binaries.
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through