From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 9913 invoked by alias); 30 Mar 2010 17:36:21 -0000 Received: (qmail 9892 invoked by uid 22791); 30 Mar 2010 17:36:20 -0000 X-SWARE-Spam-Status: No, hits=-1.9 required=5.0 tests=BAYES_00,T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from moene.org (HELO moene.org) (82.95.66.103) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Tue, 30 Mar 2010 17:36:15 +0000 Received: from [127.0.0.1] (ident=toon) by moene.org with esmtp (Exim 4.71) (envelope-from ) id 1NwfMJ-0005V7-7Z; Tue, 30 Mar 2010 19:36:11 +0200 Message-ID: <4BB2368B.6020903@moene.org> Date: Wed, 31 Mar 2010 11:33:00 -0000 From: Toon Moene User-Agent: Mozilla-Thunderbird 2.0.0.22 (X11/20090707) MIME-Version: 1.0 To: Harald Servat CC: Glenn H Sembroski , gcc-help@gcc.gnu.org, gfortran Subject: Re: Accessing C++ function with Mixed Upper/Lower case name from F90 subroutine References: <4BB2158F.7050100@physics.purdue.edu> <4BB226CF.5090409@bsc.es> In-Reply-To: <4BB226CF.5090409@bsc.es> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-IsSubscribed: yes Mailing-List: contact gcc-help-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-help-owner@gcc.gnu.org X-SW-Source: 2010-03/txt/msg00351.txt.bz2 [ Copied to the GNU Fortran mailing list - probably a better forum for this question ] Harald Servat wrote: > Hello Glenn, >> I have a problem trying to prepare a large simulation package, using >> mixed F90 and C++ routines, to compile and build under GCC (g++, and >> gfortran). The problem is I have a C++ function: Gauss() which is >> called from an F90 routine: >> x=gauss() >> >> This package was made able to build under the Intel fortran compiler by >> adding to the fortran file the Intel compile directive: >> >> !DEC$ ATTRIBUTES ALIAS:'Gauss' :: gauss >> >> I attempted to build this program using GCC where for F90 code the >> gfortran compiler option -fno-underscoring was used. >> >> Presently my fortran routine won't build. It gets the error: >> >> 485: undefined reference to `gauss' >> >> So, my question is, is there a way in GCC to enable the linker to find >> the C++ 'Gauss' method? > > I don't know if the linker supports for this directly. But you can try > with the function attribute 'alias("target")' which is documented in > [1]. It creates a new name for the same routine, so you can call it > through the two names (the original, and the aliased). > In your case, you should define in your C++ file an alias to "Gauss" > which is called "gauss". > > Besides, IIRC, ICC also supports this function attribute, so you > should be able to apply it transparently. > > [1] http://gcc.gnu.org/onlinedocs/gcc/Function-Attributes.html The Standard (as of Fortran 2003, supported by GNU Fortran and ifort) way to do this is to add the following to your Fortran code: $ cat a.f90 interface gauss function gauss() bind(c, name="Gauss") use, intrinsic :: iso_c_binding real(c_float) :: gauss end function gauss end interface gauss x = gauss() end $ gfortran -c a.f90 # The command 'nm' will show you that the right external name for the # "gauss" routine has been encoded in the object file: $ nm a.o U Gauss 0000000000000000 T MAIN__ U _gfortran_set_options 0000000000000000 r options.0.1534 Hope this helps, -- Toon Moene - e-mail: toon@moene.org - phone: +31 346 214290 Saturnushof 14, 3738 XG Maartensdijk, The Netherlands At home: http://moene.org/~toon/ Progress of GNU Fortran: http://gcc.gnu.org/gcc-4.5/changes.html