0

I have a simple hello_world.cpp program. I compiled it using g++4.4.7 on a CentOS 6.6 system. When I look at ldd a.out:

linux-vdso.so.1 =>  (0x00007fffbd79e000)
libstdc++.so.6 => /usr/lib64/libstdc++.so.6 (0x00002ab6f6819000)
libm.so.6 => /lib64/libm.so.6 (0x00002ab6f6b1f000)
libgcc_s.so.1 => /lib64/libgcc_s.so.1 (0x00002ab6f6da4000)
libc.so.6 => /lib64/libc.so.6 (0x00002ab6f6fba000)
/lib64/ld-linux-x86-64.so.2 (0x00002ab6f65f7000)

When I load a module for gcc-4.9.2, LD_LIBRARY_PATH is set to /path/to/gcc-4.9.2/lib64 and running ldd a.out yields :

linux-vdso.so.1 =>  (0x00007ffff9393000)
libstdc++.so.6 => /path/to/gcc-4.9.2/lib64/libstdc++.so.6 (0x00002b2b7c104000)
libm.so.6 => /lib64/libm.so.6 (0x00002b2b7c435000)
libgcc_s.so.1 => /path/to/gcc-4.9.2/lib64/libgcc_s.so.1 (0x00002b2b7c6b9000)
libc.so.6 => /lib64/libc.so.6 (0x00002b2b7c8cf000)
/lib64/ld-linux-x86-64.so.2 (0x00002b2b7bee2000)

QUESTION : Why is the 4.9.2 version of the gcc libraries used when LD_LIBRARY_PATH is set, even though I compiled with with 4.4.7?

This seems to pose a problem of knowing which version of a library is being used. A user may compile a program with one compiler version, load a different compiler versions (via module) and then run the executable which uses a different library version than expected.

irritable_phd_syndrome
  • 4,631
  • 3
  • 32
  • 60

1 Answers1

0

I don't know whether you're aware that the use of Environment Modules is not a necessary or normal part of using GCC, or even using multiple versions of GCC.

Setting LD_LIBRARY_PATH to override the system dynamic linker's default directory search order is a practice that has been long and loudly censured, for reasons that include the one expressed in the last paragraph of your post. See e.g. Gurus say that LD_LIBRARY_PATH is bad

Doing so within environment modules in a system tailored for the use of multiple versions of tools or toolchains can be regarded as a regulated application of a hazardous practice. In that context, however, the setting of LD_LIBRARY_PATH in your gcc-4.9.2 environment module is doing exactly what such a setting is supposed to do: overriding the dynamic linker's default directory search order. See the documentation: 3.3.1.

In principle it is possible that a program compiled and linked with an older or later version of GCC would behave unexpectedly if you choose to run it in the environment of the gcc-4.9.2 module. Environment modules are a niche convenience, and they come with this risk. Although if you built the program in the native environment, or specifically in a module-enabled environment for gcc 4.4.7, then the risk attendant on running it in your gcc-4.9.2 environment is presumably one that you don't have to take.

Community
  • 1
  • 1
Mike Kinghan
  • 55,740
  • 12
  • 153
  • 182