public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
* 'undefined reference' encountered building compface
@ 2001-02-07 20:03 Mithras
  2001-02-07 20:39 ` Mumit Khan
  0 siblings, 1 reply; 2+ messages in thread
From: Mithras @ 2001-02-07 20:03 UTC (permalink / raw)
  To: cygwin

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 <khan at NanoTech dot Wisc dot EDU>:

> 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 <netdb.h>   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:

<from compface; cmain.c>
/* 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] : "")
<more error-handling definitions follow>

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@dhp.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

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: 'undefined reference' encountered building compface
  2001-02-07 20:03 'undefined reference' encountered building compface Mithras
@ 2001-02-07 20:39 ` Mumit Khan
  0 siblings, 0 replies; 2+ messages in thread
From: Mumit Khan @ 2001-02-07 20:39 UTC (permalink / raw)
  To: Mithras; +Cc: cygwin

On Wed, 7 Feb 2001, Mithras wrote:

> 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 <khan at NanoTech dot Wisc dot EDU>:

I was hoping that post would give folks enough of a clue to do the right
thing. Here it is again: Cygwin, unlike some of the other existing Unix
systems, does not define an external variable named errno, sys_nerr and
sys_errlist. ``errno'' is actually a macro, and with more and more
multithreaded systems, that is become more common. The names of sys_nerr
and sys_errlist were at some point changed to _sys_nerr and _sys_errlist
and imported from the DLL (the fact that these are also not exported 
without the leading underscores is a mistake IMO). So, how do you handle
this?

1. Anywhere there is errno used, make sure that you include <errno.h>
and wherever you see code like the following:
  
  extern int errno;

change that to:

  #ifndef errno
  extern int errno;
  #endif

2. Anywhere you see sys_nerr and sys_errlist, make sure your code does not
declare them as:
  
  extern int sys_nerr;
  /* ... */

and instead, use the declarations provided by the runtime headers. Then
build it as following:
  
  gcc -Dsys_nerr=_sys_nerr -Dsys_errlist=_sys_errlist ...

(or change the code appropriately, or better yet, have the configuration
tools do this for you if the package is autoconfigured).

Portable code should be using the standard strerror(), not these magic 
variables anyway. 90+% of the time strerror() is you need.

Regards,
Mumit



--
Want to unsubscribe from this list?
Check out: http://cygwin.com/ml/#unsubscribe-simple

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2001-02-07 20:39 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-02-07 20:03 'undefined reference' encountered building compface Mithras
2001-02-07 20:39 ` Mumit Khan

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).