-   Linux - Newbie (
-   -   "/usr/lib/ version `GLIBCXX_3.4.9' not found" worked but stil confused (

babu198649 03-23-2008 06:50 AM

"/usr/lib/ version `GLIBCXX_3.4.9' not found" solved but stil confused

i have red hat linux installed in my system.

[babu@localhost h]$ uname -a
Linux localhost.localdomain 2.6.9-22.ELsmp #1 SMP Mon Sep 19 18:32:14 EDT 2005 i686 i686 i386 GNU/Linux

[babu@localhost h]$ cat /proc/version
Linux version 2.6.9-22.ELsmp ( (gcc version 3.4.4 20050721 (Red Hat 3.4.4-2)) #1 SMP Mon Sep 19 18:32:14 EDT 2005

the default gcc compiler version is gcc version 3.4.4 which had present in my system.

i have upgraded the gcc to version 4.2.2.

now when i compiled the program (which uses external library) ,there was no problem. but when i run the program i got the following error.

[babu@localhost h]$ ./a.out
./a.out: /usr/lib/ version `GLIBCXX_3.4.9' not found (required by ./a.out)

when i used ldd command to view the shared dependencies i got the following

[babu@localhost h]$ ldd ./a.out
./a.out: /usr/lib/ version `GLIBCXX_3.4.9' not found (required by ./a.out) => /usr/lib/ (0x00829000) => /lib/tls/ (0x00517000) => /lib/ (0x007e1000) => /lib/tls/ (0x003eb000)
/lib/ (0x003d2000)

here i have noticed that the gcc(version 4.2.2)libraries reside in /usr/local/lib

but note that in the above command the program is linked to libraries which is residing in the /usr/lib path (which is the old gcc version library path)

so i explicitly gave the library path in the command like this which points to gcc-4.2.2 version libraries.

[babu@localhost h]$ g++ -Wall simple_xy_wr.cpp /usr/local/lib/libnetcdf_c++.a /usr/local/lib/libnetcdf.a /usr/local/lib/libstdc++.a

and now its working fine and when the shared dependencies are checked i got this

[babu@localhost h]$ ldd a.out => /usr/lib/ (0x00829000) => /lib/tls/ (0x00517000) => /lib/ (0x007e1000) => /lib/tls/ (0x003eb000)
/lib/ (0x003d2000)

ie. there is no change in the dependency path but after specifying the library path while compiling its working:confused: very:confused:

now i wnt to uninstall the old gcc(which is given by distro ,how to uninstall) or
is there any other solution for this problem(such as always the gcc command links to libraries in the path /usr/local/lib/ rather than pointing to old gcc version libraries which is present in /usr/lib/ path)

bigrigdriver 03-23-2008 09:27 AM

When you link programs with libraries, the linker doesn't use the full path to the library; only the library name. The standard libraries to use are /lib and /usr/lib. Any others must be given in the compile command.

At run-time, the system will search only /lib and /usr/lib for the libraries. If they are not found, you get error messages.

To fix that, you need to add "-W1,rpath" option with the path to additional libraries, like so:
g++ -Wall simple_xy_wr.cpp /usr/local/lib/libnetcdf_c++.a /usr/local/lib/libnetcdf.a -W1,rpath,/usr/local/lib.

Now the system should search the standard /lib and /usr/lib, plus /usr/local/lib, at run-time.

Reference: Advanced Linux Programming, ch. 2, section 3.4, Library Dependencies

babu198649 03-24-2008 02:18 AM

thanks for reply

the problem with my compilation is not with the external libraries.
i had downloaded the netcdf(c and c++ libraries) package and compiled with make which had been generated by configure(configure file was given in the package)

there are examples within the main directory of the package and those examples also compile with make . now when i had checked for the dependencies(for the example programs which had been compiled with the make file and it resides within the main directory of the package) it says

[babu@localhost CXX]$ ldd simple_xy_wr => /usr/local/lib/ (0x00400000) => /usr/local/lib/ (0x007be000) => /lib/tls/ (0x00517000) => /lib/tls/ (0x00111000)
/lib/ (0x003d2000)

now i copied the same example program outside the package directory and tried to execute
and i get the problems mentioned in the above post.

the examples compiled by the package depends on libraries in the path

where as if i compile the same example and it depends on libraries in the path
/usr/lib/ which can be seen in the above post.

could u help me to uninstall the gcc compiler.the make file with which i had installed the gcc does not support uninstallation.

All times are GMT -5. The time now is 10:57 PM.