Subject: Re: Out damn DLL, out... my experience
From: [email-masked] (Fergus Henderson)

17 Jan 1998 01:26:23 -0800
Message-ID: <[email-masked]>
References: <[email-masked]>
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
To: [email-masked]
Cc: [email-masked]

On 13-Jan-1998, Joseph F. Garvey <[email-masked]> wrote:
> I had a simple desire. I wanted a tee.exe for NT, that consisted of
> one file, so that it could be copied from system to system in a mindless
> fashion. [...]
> If you have tee.exe (as distributed), you also need cygwin.dll.
> 
> How do I get rid of cygwin.dll? Colin Peter's note says:
> 
> # Steps to generate a libcygwin.a.
> impdef foo.dll > foo.def            #impdef comes from colin's web site.
> dlltool --def foo.def --output-lib libfoo.a
> 
> # Step to use libcygwin.a.
> gcc -o bar.exe bar.o -lfoo
> 
> Well, a libcygwin already exists.
> So, I can link that in and solve the problem without impdef or dlltool.

Nope.  The libcygwin.a that comes with the gnu-win32 distribution is
not a stand-alone library, it is just a stub library that contains
stubs that call cygwin.dll.  The libcygwin.a that you would obtain
using impdef and dlltool as shown above would be the same.

> I re-ran the command to link tee, but added a request to link in libcygwin.
> It worked.

Nope, it didn't.  It just *appeared* to work.
As noted previously on this list, libcygwin is linked in by default.
By linking in libcygwin explicitly, you cause it to be linked in twice.
This results in the various DLL import tables not being properly
terminated or something like that.

> Now I had a tee.exe. When I ran this tee.exe, I ended up with
> an error message "(null)" DLL not found on DLLPATH. Argggggh. Obviously,
> it had linked ok,

No.

> but something still was calling a routine looking for a DLL,

Yes.

> but now a null pointer or empty string was being passed as the name
> of the DLL.

Yes.  That's because it didn't link correctly; probably the executable's
list of DLLs is not properly terminated or something like that.

> After a lot of looking, I could find no option or clue to
> keep this from happening.

You'd need to create a libcygwin.a that was not a stub library.
This would be a fair bit of work; I think some of the code
in cygwin.dll may assume that it is running in a DLL, and may
not work if it is not.

-- 
Fergus Henderson <[email-masked]>   |  "I have always known that the pursuit
WWW: <http://www.cs.mu.oz.au/~fjh>   |  of excellence is a lethal habit"
PGP: finger [email-masked]         |     -- the last words of T. S. Garp.
-
For help on using this list (especially unsubscribing), send a message to
"[email-masked]" with one line of text: "help".