From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wm1-x335.google.com (mail-wm1-x335.google.com [IPv6:2a00:1450:4864:20::335]) by sourceware.org (Postfix) with ESMTPS id 9D604385DC14 for ; Sun, 4 Apr 2021 10:46:10 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 9D604385DC14 Received: by mail-wm1-x335.google.com with SMTP id f22-20020a7bc8d60000b029010c024a1407so6291093wml.2 for ; Sun, 04 Apr 2021 03:46:10 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=0E2F7Yk78dxd7Yc7tJ2jX5px9bg+Paq0HHfUf6cv8X0=; b=mg/jMmP0kau5nsiSlbGJnng9RSLiWcJeAJTkF0D6V5Fy54ilcd7C00rTO/fbs5nR/x bWHNEomEh53GN5G7GEBOhJHIXCEnDOYoe4xfrjTM8TLg+WopPD5LpHbfV3mt2dfEr2ni ktNSsnbxtnhgmeSGzJdI6psPK7bDSTdNPSMPc5NGJ/d1JhsX2mS5KMrwaeXAuIj4uY5H bpsIqz7VaZopQRvblN06Ju1n8Jhx5hJdWSA+IzWVDqHsU5/+cjSPQ6j2NJQNEQ1Ns2n/ xgmbmX0zX05Zne96u4+3H55/EfDGTwSZd2uIraxfz9fvRWIi+6SzZXceRvrcYpzgjstx hacQ== X-Gm-Message-State: AOAM533LUe3qUssZnM4slYjNr5JxIORfdu+mTSBCTA6HAaHQjN+N++c0 3Tn9YpwzFOKfp0VGs5osN08= X-Google-Smtp-Source: ABdhPJwD2grRiaBoFD7vtCZ8NFZ1L3/O2wxtlOYBtd+kvWw09XUq03LVeii+tk4PmNM3s2ESHUFNog== X-Received: by 2002:a1c:5fd4:: with SMTP id t203mr1629288wmb.142.1617533169678; Sun, 04 Apr 2021 03:46:09 -0700 (PDT) Received: from nbbrfq (193-154-138-37.adsl.highway.telekom.at. [193.154.138.37]) by smtp.gmail.com with ESMTPSA id o2sm18996572wmc.23.2021.04.04.03.46.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 04 Apr 2021 03:46:09 -0700 (PDT) Date: Sun, 4 Apr 2021 12:46:05 +0200 From: Bernhard Reutner-Fischer To: Harald Anlauf , Harald Anlauf via Fortran Subject: Re: gfortran, OpenMP and static linking Message-ID: <20210404124605.02773f74@nbbrfq> In-Reply-To: References: MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-3.4 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: fortran@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Fortran mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 04 Apr 2021 10:46:12 -0000 Harald, On Sat, 03 Apr 2021 23:24:52 +0200 Bernhard Reutner-Fischer wrote: > On 3 April 2021 20:55:39 CEST, Harald Anlauf via Fortran 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