public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
From: gvaughan@oranda.demon.co.uk (Gary V. Vaughan)
To: DJ Delorie <dj@delorie.com>
Cc: scarpe@atos-group.com, cygwin@sourceware.cygnus.com
Subject: Re: Making DLL's.
Date: Wed, 31 Mar 1999 19:45:00 -0000	[thread overview]
Message-ID: <u1zihvmrf.fsf@oranda.demon.co.uk> (raw)
Message-ID: <19990331194500.88HGIhPl32H9Dozd1f5wzB7IdLh0ASIQSnmXJaelfSo@z> (raw)
In-Reply-To: <199903191530.KAA01054@envy.delorie.com>

DJ Delorie <dj@delorie.com> writes:

> > Can't anyone out there make "ld -b" produce dll (or may be some .so
> > file, but may be i'm dreaming awaken) so that we can have a real
> > standard way to build shared library ?
> 
> I've already done it, it just hasn't been released with cygwin yet.
> Basically, "ld -shared *.o foo.def -o foo.dll" will work in the new
> version (or gcc -Wl,-shared ...)

First; another answer:

The upcoming libtool release, and to a marginally lesser extent, the most
recent alpha release ( ftp://alpha.gnu.org/pub/gnu/libtool/libtool-1.2f.tar.gz ),
make a pretty decent stab at both building dlls, and linking against them
in a cygwin environment.

Then a question:

The only fly in the ointment for libtool's dll support is handling the export
of data items from a dll.  Specifically, an object that will be linked into
an executable which will in turn be linked with a handful of libraries (some
static and some dll's, for argument's sake) needs to produce different code
depending on what particular combinations of dll and static libraries it will
ultimately be linked with.

That is I need to make sure that any data item that will be imported from a
dll has __attribute__((dllimport)), and any data item imported from a static
library cannot have this attribute.  Obviously, in a makefile driven build
environment there is no easy way to know which combination of libraries this
object will eventually be linked with... is there a way around this problem?
Or do I have to come up with some kind of makefile scanner to figure out
which attributes to attach to each symbol?

Actually, libtool compounds the problem, because it wants to produce both
static and dll libraries for each library object, and thus a given data symbol
may be:
        1) exported from this object if the object will be part of a dll
        2) imported from another dll
        3) imported from a static library
        4) externed in the tradition way if it will be part of a static lib

So, my question is:  do I really have to figure out whether this object is
destined to become part of a static library, a dll, or an executable, and
which libraries that destination will depend on and whether each of them will
be a dll or not in order to produce the correct code for each exported data
symbol?

My (flawed) best solution so far is:

        /* foo.h */
        #ifdef __CYGWIN__
        #  ifdef _COMPILING_FOO_DLL_
        #    define EXTERN __declspec(dllexport)
        #  else
        #    define EXTERN extern __declspec(dllimport)
        #  endif
        #else
        #  define EXTERN extern
        #endif

        EXTERN int foo;

When building the dll, I need:

        /* foo.c */
        #define _COMPILING_FOO_DLL_
        #include "foo.h"

When linking against the dll on cygwin or otherwise:

        /* bar.c */
        #include "foo.h"

Which works fine, until I try to build an equivalent static libfoo.a from the
foo sources on cygwin, when ofcourse I get `undefined __imp_foo' errors =(O|

What now?

Cheers,
        Gary.
-- 
  ___              _   ___   __              _             
 / __|__ _ _ ___ _| | / / | / /_ _ _  _ __ _| |_  __ _ ___ 
| (_ / _` | '_|// / |/ /| |/ / _` | || / _` | ' \/ _` | _ \
 \___\__,_|_|\_, /|___(_)___/\__,_|\_,_\__, |_||_\__,_|//_/
PGP Key from/___/                      /___/               
http://www.cl.cam.ac.uk/PGP/pks-commands.html#extract      
http://pgp.ai.mit.edu/~bal/pks-commands.html#extract       


--
Want to unsubscribe from this list?
Send a message to cygwin-unsubscribe@sourceware.cygnus.com


  reply	other threads:[~1999-03-31 19:45 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1999-03-18 13:07 Serguei DACHIAN
1999-03-19  3:30 ` Paul Sokolovsky
1999-03-19  6:01   ` Sebastien Carpe
     [not found]     ` < 36F258AB.CC1A1788@atos-group.com >
1999-03-19  7:30       ` DJ Delorie
1999-03-22  2:32         ` Gary V. Vaughan [this message]
1999-03-22  7:28           ` John Mullee
1999-03-22  8:56             ` Gary V. Vaughan
1999-03-22 11:15               ` Re[2]: " Paul Sokolovsky
     [not found]                 ` < 3887.990322@is.lg.ua >
1999-03-22 22:25                   ` Mikey
1999-03-23  2:32                     ` Gary V. Vaughan
1999-03-31 19:45                       ` Gary V. Vaughan
1999-03-24  4:35                     ` Re[4]: " Paul Sokolovsky
1999-03-31 19:45                       ` Paul Sokolovsky
1999-03-31 19:45                     ` Re[2]: " Mikey
1999-03-23  1:13                 ` Gary V. Vaughan
1999-03-31 19:45                   ` Gary V. Vaughan
1999-03-31 19:45                 ` Paul Sokolovsky
1999-03-31 19:45               ` Gary V. Vaughan
1999-03-31 19:45             ` John Mullee
     [not found]           ` < u1zihvmrf.fsf@oranda.demon.co.uk >
1999-03-22 14:50             ` Fergus Henderson
1999-03-23  1:47               ` Gary V. Vaughan
1999-03-31 19:45                 ` Gary V. Vaughan
1999-03-31 19:45               ` Fergus Henderson
1999-03-31 19:45           ` Gary V. Vaughan
1999-03-31 19:45         ` DJ Delorie
1999-03-31 19:45     ` Sebastien Carpe
1999-03-31 19:45   ` Paul Sokolovsky
1999-03-31 19:45 ` Serguei DACHIAN
1999-03-21 15:04 Serguei DACHIAN
     [not found] ` < 1.5.4.32.19990321230358.00671530@lola.univ-lemans.fr >
1999-03-21 15:47   ` Mumit Khan
1999-03-31 19:45     ` Mumit Khan
1999-03-31 19:45 ` Serguei DACHIAN

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=u1zihvmrf.fsf@oranda.demon.co.uk \
    --to=gvaughan@oranda.demon.co.uk \
    --cc=cygwin@sourceware.cygnus.com \
    --cc=dj@delorie.com \
    --cc=scarpe@atos-group.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).