Mailing-List: contact cygwin-help AT sourceware DOT cygnus DOT com; run by ezmlm List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner AT sources DOT redhat DOT com Delivered-To: mailing list cygwin AT sources DOT redhat DOT com Date: Wed, 7 Feb 2001 23:03:05 -0500 (EST) From: Mithras To: cygwin AT cygwin DOT com Subject: 'undefined reference' encountered building compface Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Hi, I'm running cygwin on Win2k, I'd like to build Xemacs myself to tweak the memory management. My problem is that compface, which the Xemacs install HOWTO says hasn't been changed in generations, fails to build on some very standard symbols: $ make gcc -g -o compface cmain.o compface.o libcompface.a cmain.o(.text+0x25a): undefined reference to `errno' cmain.o(.text+0x260): undefined reference to `sys_nerr' cmain.o(.text+0x267): undefined reference to `errno' cmain.o(.text+0x275): undefined reference to `sys_errlist' I've searched for previous discussion, and the closest I've found so far is from 'Using h_errno, errno etc Cygwin DLL globals [Re: Making wget]' by Mumit Khan : > On Wed, 26 Jan 2000, Glenn Spell wrote: > > On 26 Jan 2000 around 9:38AM (-0000) Norling, Gunnar wrote: > > > Some days ago there where a discussion involving the wget program. > > > > > > ftp.o(.text+0x848):ftp.c: undefined reference to `h_errno' > > > http.o(.text+0x750):http.c: undefined reference to `h_errno' ... > > The following patch worked for me... > > I have no idea why this is necessary for some and not for > > others. > > Here's why: older versions of Cygnus didn't add the DATA tag when > exporting h_errno, and so linking worked even for incorrect code; > however, you'll get an ACCESS_VIOLATION or segfault when you try to > access or assign to h_errno. Newer Cygwin snapshots enforce the > correct behaviour so that you have to import it explicitly. Consider > the following code: > > void > foo () > { > extern int h_errno; h_errno = 5; > } > > This code is incorrect, but would have linked correctly with older > versions of Cygwin (eg., b20.1), and you'll surely get a crash if > `foo' is ever called. The correct way: > > #include void > foo () > { > h_errno = 5; > } > > The same thing applies to all the other imported data symbols (ie., > global variables) from Cygwin DLL, such as errno, etc. Mumit's remark about older versions of Cygnus made me think about the old code in compface. Compface declares errno, sys_errlist & sys_nerr directly, as in Mumit's first example: /* error handling definitions follow */ extern int errno, sys_nerr; extern char *sys_errlist[]; extern void exit P((int)) ; #define ERR ((errno < sys_nerr) ? sys_errlist[errno] : "") Apparently the Right Thing to Do is to replace the declarations of errno & friends with the appropriate standard header include... but which header? The only include files in my cygwin distribution that define these guys lie in /usr/include/mingw/, which I'd think serves as an alternative to the cygwin1.dll, not a prerequisite for cygwin builds. Looking back at the command that caused the errors, gcc -g -o compface cmain.o compface.o libcompface.a I recall that the C compiler, when it's generating a final executable, links with certain standard libraries & stubs. The issue would be with these files which don't in my instance provide 'errno', 'sys_errlist' and 'sys_nerr'. Why not? They're ANSI standards, aren't they? What can be done if they're not being provided, as they should? Am I making any sense? thanks in advance, ben taylor mithras AT dhp DOT com / http://www.dhp.com/~mithras "If you buy a person a ticket, they'll see a movie that day. But if you show a person how to sneak in, they'll see movies for a lifetime." Mark Stanley, _Freefall_, http://www.purrsia.com/freefall/ -- Want to unsubscribe from this list? Check out: http://cygwin.com/ml/#unsubscribe-simple