Harald, On Sat, 03 Apr 2021 23:24:52 +0200 Bernhard Reutner-Fischer <rep.dot....@gmail.com> wrote:
> On 3 April 2021 20:55:39 CEST, Harald Anlauf via Fortran > <fortran@gcc.gnu.org> wrote: > >Dear all, > > > >is there a reason that one should not be able to statically link a > >Fortran binary that has been compiled with -fopenmp? > > Maybe Jakub knows more on this. > > Not sure if static linking with glibc is still discouraged (it was, at least > in former times) or if thread cancellation still is supposed to work in a > pure static build. You can try to get away with linking libpthread in like below. However, glibc is (still) not supposed to be linked statically (don't ask me, i didn't write it). HTH, $ cat omp.f90 use omp_lib !$omp parallel write(*,*) "thread ", omp_get_thread_num() !$omp end parallel end $ gfortran -o omp -fopenmp omp.f90 -static -Wl,--whole-archive -lpthread -Wl,--no-whole-archive && OMP_NUM_THREADS=2 ./omp /usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/10/libgomp.a(target.o): in function `gomp_target_init': (.text+0x358): warning: Using 'dlopen' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking thread 0 thread 1