NogginBoink
Posts: 9
Joined: Fri Apr 26, 2013 2:38 pm

Dynamically linked libraries

Fri Apr 26, 2013 3:42 pm

I'm writing code that uses the Apache Thrift RPC library. (This is quite an ambitious project for someone as ignorant as I am about Linux.)

I managed to download, build, and install thrift. I managed to compile and link my code against the thrift headers. (Itself, a significant accomplishment for me.)

When I run my code, however, I get an error "Appname: error while loading shared libraries: libthrift-0.9.0.so: cannot open shared object file: No such file or directory"

I have confirmed taht libthrift-0.9.0.so resides in /usr/local/lib/ on my R-Pi.

I know absolutely nothing about how Linux locates and loads shared libraries. What do I need to do to allow my code to load this library?

NogginBoink
Posts: 9
Joined: Fri Apr 26, 2013 2:38 pm

Re: Dynamically linked libraries

Sat Apr 27, 2013 1:10 pm

I found that if I set the LD_LIBRARY_PATH in the shell, my app would run:

Code: Select all

export LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH
./MyApp
I edited /etc/profile to make this a permanent part of my environment.

User avatar
jojopi
Posts: 3046
Joined: Tue Oct 11, 2011 8:38 pm

Re: Dynamically linked libraries

Sat Apr 27, 2013 1:33 pm

/usr/local/lib should already be configured as a system-wide library path; see /etc/ld.so.conf.d/libc.conf.

However, not all of the system library directories are searched every time a process starts. Their contents are indexed in /etc/ld.so.cache, to speed up dynamic linking.

After you install a new library into a system directory you must run "sudo ldconfig" to update the cache.

Return to “C/C++”