Search code examples
c++pathshared-librariesopenmp

libgomp.so.1: cannot open shared object file


I am using OpenMP in my C++ code.

The libgomp.so.1 exists in my lib folder. I also added its path to the LD_LIBRARY_PATH

Still at run-time I get the error message: libgomp.so.1: cannot open shared object file

At Compile time I compile my code with -fopenmp option.

Any idea what can cause the problem?


Solution

  • Use static linking for your program. In your case, that means using -fopenmp -static, and if necessary specifying the full paths to the relevant librt.a and libgomp.a libraries.

    This solves your problem as static linking just packages all code necessary to run you program together with your binary. Therefore, your target system does not need to look up any dynamic libraries, it doesn't even matter if they are present on the target system.

    Note that static linking is not a miracle cure. For your particular problem with the weird hardware emulator, it should be a good approach. In general, however, there are (at least) two downsides to static linking:

    • binary size. Imagine if you linked all your KDE programs statically, so you would essentially have hundreds of copies of all the KDE/QT libs on your system when you could have just one if you used shared libraries
    • update paths. Suppose that people find a security problem in a library x. With shared libraries, it's enough if you simply update the library once a patch is available. If all your applications were statically linked, you would have to wait for all of these developers to re-link and re-release their applications.