Set path to library in linux

set library path for current script [closed]

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 

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.

2 Answers 2

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)

Читайте также:  Xerox 3155 linux driver

Источник

How do you specify the location of libraries to a binary? (linux)

For this question I’ll be using a specific example, but really this generalizes to pretty much any binary on linux that can’t seem to find its’ dependent libraries. So, I have a program that won’t run because of missing libraries:

./cart5: error while loading shared libraries: libcorona-1.0.2.so: cannot open shared object file: No such file or directory 
linux-vdso.so.1 => (0x00007fff18b01000) libcorona-1.0.2.so => not found libstdc++.so.6 => /usr/lib/gcc/x86_64-pc-linux-gnu/4.4.3/libstdc++.so.6 (0x00007f0975830000) libm.so.6 => /lib/libm.so.6 (0x00007f09755af000) libgcc_s.so.1 => /lib/libgcc_s.so.1 (0x00007f0975399000) libc.so.6 => /lib/libc.so.6 (0x00007f0975040000) libz.so.1 => /lib/libz.so.1 (0x00007f0974e2b000) /lib64/ld-linux-x86-64.so.2 (0x00007f0975b36000) 
oliver@human$ find / -name libcorona-1.0.2.so 2> /dev/null /usr/local/lib64/libcorona-1.0.2.so /home/oliver/installed/corona-1.0.2/src/.libs/libcorona-1.0.2.so 

3 Answers 3

For a once-off, set the variable LD_LIBRARY_PATH to a colon-separated list of directories to search. This is analogous to PATH for executables, except that the standard system directories are additionally searched after the ones specified through the environment.

LD_LIBRARY_PATH=/usr/local/lib64 ./cart5 

If you have a program that keeps libraries in a non-standard location and isn’t able to find them on its own, you can write a wrapper script:

#!/bin/sh if [ -n "$LD_LIBRARY_PATH" ]; then LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib64 else LD_LIBRARY_PATH=/usr/local/lib64 fi export LD_LIBRARY_PATH exec /path/to/cart5 "$@" 

The list of standard system directories is kept in /etc/ld.so.conf . Recent systems allow this file to include other files; if yours contains something like include /etc/ld.so.conf.d/*.conf , create a new file called /etc/ld.so.conf.d/mala.conf containing the directories you want to add. After you change /etc/ld.so.conf or an included file, run /sbin/ldconfig for your changes to take effect (this updates a cache).

( LD_LIBRARY_PATH also applies to many other unices, including FreeBSD, NetBSD, OpenBSD, Solaris and Tru64. HP-UX has SHLIB_PATH and Mac OS X has DYLD_LIBRARY_PATH . /etc/ld.so.conf has analogs on most unices but the location and syntax differs more widely.)

Читайте также:  Ngrok for kali linux

Источник

Specify location of static libraries for C++ application in Linux

first of all, I hope that I ask the question in the right context here. I build an application in C++ with Code::Blocks. The application uses static libraries that are provided by a third party and cannot be installed on a system via the package management. Therefore I ship these libraries when I distribute my application. Here is what my target configuration looks like:

I can build this target fine and run it. Everything works. Today, I tried to run in on Debian Squeeze and just copied a folder which contained both the executable and the libraries from the third party. I thought that as long as everything is in one folder the executable will find the .so files. I was wrong. I get the message:

/home/my_app/my_app: error while loading shared libraries: lib1.so: cannot open shared object file: No such file or directory 

I don’t get this message on my developement machine because Code::Blocks is able to set a working directory for the executable. I could remove the error message by putting the location of the .so files inside /etc/ld.so.conf.d/my_app.conf. Is there anyway I can build the executable so it searches the libs in the execution directory? Or this is a problem specific for Debian? Or can I specify the working directory for the process before I execute the executable? I want to avoid changing the systems configuration / environment before you can start the application.

Источник

How to set the path that a .so library will search for other .so libraries?

I have a libA.so that depends on libB.so, which is located at ../libB/ (from libA.c). I’m trying to compile things in such a way that I don’t have to set any environment variables. I have:

 cc -std=c99 -c -fPIC -I../libB/ -Wall libA.c cc -std=c99 -shared libA.o -L../libB -lB -o libA.so 
dyld: Library not loaded: libB.so Referenced from: libA/libA.so Reason: image not found Trace/BPT trap: 5 

so libA is not finding libB at runtime. I found this solution to change the runtime path on Mac OS X: install_name_tool -change libB.so @loader_path/../libB.so libA.so but I’d like to find a solution that would work on both OS X and Linux. Again, I’m trying to make the end-user do as little as possible so I don’t want them to have to set environment variables, and I have to use cc (which for me is Apple LLVM version 4.2 (clang-425.0.27) (based on LLVM 3.2svn), and I’d like for it to work on Linux too, so presumably cc=gcc there). EDIT My problem may be more complicated than I realized. I’m making this dynamic library in C, but trying to use it from within python. I can use libB.so (which has no dependencies) from within python no problem, and when I load libA.so from within python it finds it (see error above), it’s just that at that point libA.so realizes it doesn’t know where to find libB.so. If I understand your answers correctly below, the solutions depend on setting the linker path when you compile the executable, which in my case is in python. Is there no way to tell libA.so where to look for libB.so when I compile it? I can do it afterward with install_name_tool on OSX, but is there not a way with the compiler that would work on both OSX and linux?

Читайте также:  Создать собственный дистрибутив linux

Источник

Оцените статью
Adblock
detector