Projet C IG (1A)

IHM (2A)


VR/AR/Post-WIMP (3A)


Projet image (2A)


HCI (MoSIG 2)


Test Logiciel


Projects Docs

Fixing the problem of missing libraries

The problem

When you compile a program, you may use functions that are already compiled in shared libraries. Shared libraries have names that end with .so on linux, .dylib on Mac OS, and .dll on windows.

You may tell the linker to look for functions in shared libraries with commands such as:

 g++ main.cpp -o test -L/home/toto/my_shared_libraries -lshl

On linux or Mac OS, this tells the compiler/linker to compile "main.cpp" into a program "test", and to look for pre-compiled functions in the shared library "libshl.so" (on Linux) or "libshl.dylib" (on Mac OS). The "lib" prefix and ".so" or ".dylib" suffix are implicitly added by the linker. The linker will search into the standard system directories for this file (i.e. /usr/lib, /usr/local/lib, etc.). In this example, we explicitly tell the linker to also look into the "/home/toto/my_shared_libraries" directory.

When the compilation succeeds, you may want to execute your program with:

 ./test

but this will probably fail. That's because when the "test" binary was linked with the first command, the full path of the shared library was not included in "test" (see "Debugging" below to list the shared libraries that are linked with a program and their paths). The loader reads in the "test" binary that it needs "libshl.so", but it does not find it in the standard system directories. You can fix that by setting an environment variable.

Environment variable for shared library paths

Systems use an environment variables to store the list of additional directories to search for shared libraries when loading programs (for execution). The name of the variable depends on the system:

        LinuxLD_LIBRARY_PATH
 Mac OSDYLD_LIBRARY_PATH
 WindowsPATH


On UNIX (Mac OS and Linux), separate multiple directories with colons (:). Use semicolons (;) on Windows.

Examples

 # with tcsh
 setenv LD_LIBRARY_PATH "/home/toto/my_shared_libraries:/home/toto/OpenSceneGraph3.4.0/lib64"

 # with bash
 export LD_LIBRARY_PATH="/home/toto/my_shared_libraries:/home/toto/OpenSceneGraph3.4.0/lib64"

On Windows, you need to find the System Properties dialog box. Usually, you can get it from

 <Control Panel><System and Security><System><Advanced system settings>

The System Properties dialog box has an Environment Variables... button at the bottom. The "Path" or "PATH" variable should be already defined. You can update it either at the user level (only your login) or at the system level (all users).

Debugging

You can use tools to analyze a program and know which shared libraries it depends on: "ldd" on Linux, "otool -L" on Mac OS, and dependency walker on windows.

Example:

 > ldd bin/osgviewer 
	linux-vdso.so.1 =>  (0x00007ffcfb78d000)
	libosgViewer.so.130 => /tmp/OpenSceneGraph/lib/libosgViewer.so.130 (0x00007fee3fadd000)
	libosg.so.130 => /tmp/OpenSceneGraph/lib/libosg.so.130 (0x00007fee3eb5f000)
	libstdc++.so.6 => /usr/lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007fee3e7c1000)
	libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007fee3e5ab000)
	libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007fee3e1e2000)
 (...)
Edit - History - Upload - Print - Recent Changes - Search
Page last modified on October 25, 2016, at 06:57 AM