0

I am attempting to compile

me@e:~/Dir$ gcc -O4 -o new new.c -Wall -pedantic -std=gnu11 -lm -fopenmp -static

which gives a warning

/usr/lib/gcc/x86_64-linux-gnu/5/libgomp.a(target.o): In function `gomp_target_init':
(.text+0xba): warning: Using 'dlopen' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking

The goal is to make this program statically linked so 'new' will run on my laptop and the server.

how can I use 'shared libraries from the glibc version used for linking' in gcc or clang?

con
  • 5,767
  • 8
  • 33
  • 62
  • 1
    There is no `-O4` optimization level (it will just do -O3). With the information you provided, there isn't much anybody can do. `dlopen` explicitly loads a shared library: it does not make much sense to use if you want to statically build a single binary executable. – Jorge Bellon Dec 08 '16 at 20:56
  • @JorgeBellón gcc gives the same error without regard to optimization. This error only comes with fopenmp, why? – con Dec 08 '16 at 21:03
  • @con, Jorge already told you: you are building a binary that includes at least one call to `dlopen()`, which *manually* loads a shared library at runtime. GCC is warning you about that, in part because it recognizes that that may not be what you want given that you are performing static linking. The call comes from one of the functions in `libgomp`, which is GCC's OpenMP support library; it is linked in when you ask for OpenMP via the `-fopenmp` option, but not when you don't. – John Bollinger Dec 08 '16 at 21:22
  • Note also that it might not be necessary to link statically for your binary to work on multiple machines. For example, if the two machines are running the same major version of the same Linux distribution then chances are excellent that a dynamically-linked version will run in both places, though you might need to install additional shared libraries. (And managing that sort of concern is an excellent reason to use your distro's packaging system.) – John Bollinger Dec 08 '16 at 21:27
  • @JohnBollinger is there any way I can compile the executable with fopenmp so it will run on both computers? – con Dec 08 '16 at 22:11
  • You can create a dynamic executable where glibc is linked dynamically and the other libraries statically. This should be enough in the vast majority of cases. – n. m. could be an AI Mar 08 '18 at 10:52
  • You haven't even tried if _the executable with fopenmp_ _will run on both computers_. As long as `gomp_target_init` isn't used, the warning is irrelevant, and even if it is used, `new` might run. – Armali Jun 11 '18 at 06:37

0 Answers0