Bug 57123 - code compiled and linked with -fopenmp does not load the correct omp library at run-time
Summary: code compiled and linked with -fopenmp does not load the correct omp library ...
Status: RESOLVED INVALID
Alias: None
Product: gcc
Classification: Unclassified
Component: driver (show other bugs)
Version: 4.7.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-04-30 11:48 UTC by wd11
Modified: 2013-04-30 12:12 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description wd11 2013-04-30 11:48:31 UTC
code compiled and linked with -fopenmp will, at run-time, load the first libgomp it finds in the LD_LIBRARY_PATH (on linux). However, this may not be the correct one, causing run-time failure. This problem manifests itself if, for example, using a more recent version of gcc (4.7.0) than the default OS version (4.3.4), when upon running I get

mycmd: /usr/lib64/libgomp.so.1: version `OMP_3.0' not found (required by mylib.so)

where mycmd was made using gcc 4.7.0 (at /somepath/gcc/4.7.0/bin/gcc) with option -fopenmp both at compiling and linking. This behaviour is at odds with the documentation, according to which -fopenmp arranges for the automatic linking of the [correct] OpenMP library.

Note that I can "fix" the problem by adding the path of the correct library, /somepath/gcc/4.7.0/lib64, to the environment variable LD_LIBRARY_PATH. However, this fiddling with the operating system is not desirable and potentially dangerous, as it may break the operating system itself. Instead, the correct library path should be hard-wired into the executable upon making it, i.e. at linking the -fopenmp option should effectuate to (-Wl) -rpath=/somepath/gcc/4.7.0/lib64. Note also that adding the correct path to the LD_RUN_PATH environment variable at compiling and linking (and running) has not the desired effect.
Comment 1 Jakub Jelinek 2013-04-30 12:12:05 UTC
That is a user error, gcc isn't supposed to handle this for you.  If you have multiple versions of libgomp.so on your system, just use -Wl,-rpath,/some/path/
or LD_LIBRARY_PATH to point the program at the right version.
Like glibc, libgomp is symbol versioned and backward compatible, keeping the same SONAME, so you really want the latest version of the library from all versions needed by programs that link against it.