This is the mail archive of the cygwin mailing list for the Cygwin project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: _set_fmode?

On Mar 18 08:41, Charles Wilson wrote:
> Corinna Vinschen wrote:
> > On Mar 17 21:15, Charles Wilson wrote:
> >>
> >> +#if defined(_WIN32) && !defined(__CYGWIN__)
> > The !defined(__CYGWIN__) is not necessary because gcc for Cygwin
> > doesn't define _WIN32.
> gcc does not define it. But the w32api headers DO.

Hmpf, right.

> >   extern int _fmode;
> >   _fmode = O_BINARY;
> I didn't know you could access it directly, outside of cygwin1.dll.

Well, it's defined in the application itself.

> > But anyway, using binmode.o is much more elegant, IMHO.  I don't see
> > what speaks against using it.
> Well, now that I see libbinmode.a, nothing.

Don't use the libFOOmode.a files.  They don't do what you want.
Actually I think we should remove them better sooner than later.

The mechanism works like this:  The FOOmode.a files provide a function
cygwin_premain0, which sets _fmode to the desired value.  Cygwin itself
needs these functions to work and if no other file provides these
functions they are linked from the empty default functions provided by

The problem is, if the functions are not provided by an object file, but
by a library, they are not used.  This works:

  $ gcc -o foo foo.c /lib/binmode.o (-lcygwin through gcc specs)

/lib/binmode.o adds the function cygwin_premain0 to the link line,
which is then requested in libcygwin.a.  All is well.

This doesn't work:

  $ gcc -o foo foo.c -lbinmode (-lcygwin)

/lib/libbinmode.a provides the function cygwin_premain0, but up to the
point where libbinmode.a is linked in, there was no request to link in a
function called cygwin_premain0.  So nothing's linked in from
libbinmode.a.  Then libcygwin.a requests the function and provides it

  $ gcc -o foo foo.c -lcygwin -lbinmode (-lcygwin)

Same here.  libcygwin.a requests and already provides the function, so
it's too late for libbinmode.a.

> But using /usr/lib/binmode.o in your build rules is non-portable, and
> breaks cross-compiles (my linux box doesn't have that file, and even if
> it did it wouldn't be cygwin's).  gcc doesn't search the -L path for
> .o's, so you can't just specify 'binmode.o', you have to give the full
> path.  So I was stuck with a patch that would not be acceptable
> upstream, to explicitly add "/usr/lib/binmode.o" to the LDADD variable
> with an AM_CONDITIONAL on $host=cygwin. Ugly.

Weird.  My patch to link against textreadmode.o by adding it to $LIBS
in configure has been accepted by upstream OpenSSH.  No problem.

> At least now, I see that I can use an AM_CONDITIONAL to add -lbinmode to
> LDADD, which is much cleaner and actually works on cross builds.

See above.


Corinna Vinschen                  Please, send mails regarding Cygwin to
Cygwin Project Co-Leader          cygwin AT cygwin DOT com
Red Hat

Unsubscribe info:
Problem reports:

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]