Mailing-List: contact cygwin-help AT sourceware DOT cygnus DOT com; run by ezmlm Sender: cygwin-owner AT sourceware DOT cygnus DOT com Delivered-To: mailing list cygwin AT sourceware DOT cygnus DOT com X-Authentication-Warning: modi.xraylith.wisc.edu: khan owned process doing -bs Date: Mon, 10 May 1999 11:31:16 -0500 (CDT) From: Mumit Khan Reply-To: Mumit Khan To: "J.C. Ng" cc: cygwin AT sourceware DOT cygnus DOT com Subject: Re: No underscore option for g77 or f77 In-Reply-To: Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII On Mon, 10 May 1999, J.C. Ng wrote: > The library was compiled using egcs 1.1.2 in Cygwin. I used nm to check > the symbols within the library and all of them was prepended an > underscore. > Thanks for your help. So you're trying to call g77 compiled routines from C/C++ and vice versa and running the "underscore issue". There is lots of info on the net on how to semi-portably do this, and I won't rehash that here. Here's a quick summary of what I do: 1. at compile time (via configuration utility), check if the f77 compiler tacks an underscore at the end. If so, define F77_APPEND_UNDERSCORE to be 1, or else 0 (or undefine it). 2. In C headers, when prototyping the functions, I use this macro to declare the externals: #if F77_APPEND_UNDERSCORE # define F77_FUNCTION(f) f##_ #else # define F77_FUNCTION(f) f #endif extern int F77_FUNCTION(f77func1) (int *, int *); or, if you want to define or undefine F77_UNDERSCORE (instead of giving it a value), #if defined(F77_APPEND_UNDERSCORE) # define F77_FUNCTION(f) f##_ #else # define F77_FUNCTION(f) f #endif extern int F77_FUNCTION(f77func1) (int *, int *); You can simply build all your C code with -DF77_APPEND_UNDERSCORE=1 and you're all set. G77, thanks to compatibility with f2c, has one more issue -- it appends *TWO* underscores if the name already has an underscore. Of course, names with underscores are not legal in f77, so f2c is free to do as it wishes. There are good portability packages out there that may help. Lots of people use CFORTRAN, which is a terrific package that hides lots of this magic. You need to get version 3.5. Also search the mailing list for what else you may need. Regards, Mumit -- Want to unsubscribe from this list? Send a message to cygwin-unsubscribe AT sourceware DOT cygnus DOT com