Error Loading Shared Libraries

Hi guys, first post!

New to C++, Linux (Ubuntu 10.04) and CodeBlocks and wasn't sure whether to put this into the beginner section or here.

Am trying to compile a simple program that uses some acml math library, located in
"/opt/acml4.4.0/gfortran32_mp/lib/libacml_mp.so"

I also have the respective header file:
"/opt/acml4.4.0/gfortran32_mp/include/acml.h"

Now I create a new empty project on CodeBlocks and Add the Linker file (.so) along with setting the include directories to add the header file. Compilation runs fine in both debug and Release mode, but when I try run the application, I get the error:
./AcmlNIckTry: error while loading shared libraries: libacml_mp.so: cannot open shared object file: No such file or directory

I have tried to find solutions for this problem and what i understand till now is that the program is trying to call the .so file but cant find it. This led me to try learn what a .so file really it turns out to be equivalent to .dll (which I don't know much about either). There is also a ".a" file in the same folder as the ".so" one but using that as a linker file in codeblocks results in errors.

And finally i ran "ldd <myprogram>" and get the following output
1
2
3
4
5
6
7
8
        linux-gate.so.1 =>  (0xb781a000)
	libacml_mp.so => not found
	libstdc++.so.6 => /usr/lib/libstdc++.so.6 (0xb7709000)
	libm.so.6 => /lib/tls/i686/cmov/libm.so.6 (0xb76e2000)
	libgcc_s.so.1 => /lib/libgcc_s.so.1 (0xb76c3000)
	libc.so.6 => /lib/tls/i686/cmov/libc.so.6 (0xb7569000)
	libpthread.so.0 => /lib/tls/i686/cmov/libpthread.so.0 (0xb7550000)
	/lib/ld-linux.so.2 (0xb781b000)


As I said I am a beginner, so if I haven't provided enough detail here about my problem, please let me know what else I can provide. Thanks in advance
Update::

Problem Fixed! I copied libacml_mp.so to directory /usr/local/lib/ and ran program

Questions: Seems kind of tedious to manually copy the .so file. Is there any way I can tell to program to look at the original directory : "/opt/acml4.4.0/gfortran32_mp/lib/libacml_mp.so" instead??
Or is this a setting that I can change in Code::Blocks??

Also been looking into LD_LIBRARY_PATH, which I am guessing are the directories for an application to look at for libraries.
To test it out I tried
export LD_LIBRARY_PATH="/opt/acml4.4.0/gfortran32_mp/lib/libacml_mp.so"
and I still get "not found" for my library when running ldd. Am I doing something wrong?
Is there a way to see all the directories that are already in LD_LIBRARY_PATH ??
Update::

According to the one of the Ubuntu posts (https://help.ubuntu.com/community/EnvironmentVariables),
LD_LIBRARY_PATH can no longer be set unless you are in an interactive shell (don't know what that is)
So a work around is: Folder "/etc/ld.so.conf.d/" holds .conf files that contain links to paths of different libraries. Here you can add your own .conf file to support your code.
e.g. from the terminal type in:
echo "<path to libraries>" | sudo tee /etc/ld.so.conf.d/<make your name>.conf

So for my acml libraries:
echo "/opt/acml4.4.0/gfortran32_mp/lib" | sudo tee /etc/ld.so.conf.d/acml-libs.conf

and then run sudo ldconfig -v which updates this list

Learning so much :)
Last edited on
closed account (S6k9GNh0)
Why is the library in such a strange place?
Basically, if you want to use LD_LIBRARY_PATH to find the .so in the directory where it was, you should add it somewhere like your .bashrc file:

export LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:/opt/acml4.4.0/gfortran32_mp/lib

(To see what is in LD_LIBRARY_PATH at any given time, just do:
echo $LD_LIBRARY_PATH
)

Modifications to environment variables only take effect in the shell in which the modification is made and any subshell created by that shell.
interactive shell (don't know what that is)


It's something that often looks like this:

http://i1-news.softpedia-static.com/images/reviews/large/bash_tutorial-img2-large.png

It's the command line.
Topic archived. No new replies allowed.