[Gambas-devel] [FWD]Re: Possible cygwin port

Brandon Bergren bdragon at ...185...
Mon Nov 15 19:54:04 CET 2004


Hello, list.

Quoting Benoit Minisini <gambas at ...1...>:

> On Thursday 11 November 2004 16:08, you wrote:
> > Hello, Benoît,
> 
> Hi,
> 
> >
> > My name is Brandon Bergren.  I have some experience with Windows porting.
> > Yesterday, I looked into the feasibility of porting Gambas to Cygwin. 
> > There are only two problems as far as I can see, plus one small patch.
> >
> > The patch is attached. It fixes the only actual build error in the C code.
> >
> > Libtool runs fine on cygwin, but there is a major caveat -- Shared
> > libraries must implicitly declare all symbols. (Since Cygwin uses the DLL
> > type of linkage, dll's implicitly declare their IMPORTS, as well as their
> > exported symbols.)
> > That is the only way to easily support shared libraries on Windows.
> >
> > You must use -no-undefined when using libtool in link mode.  Here's the
> > autoconf macro for telling autotools that the libraries are cygwin ready:
> >
> 
> OK, I added this flag in "LDFLAGS".

Err, using -no-undefined is only needed on Cygwin shared libs.  Other platforms
support "lazy loading", but Cygwin doesn't, as the implementation is currently
a hack using Win32 DLLs (which require all imports and exports to be explicitly
stated -- The win32 runtime linker is way different than the GNU one.)

Actually, using this flag would probabaly break builds.  Having a configure
option to enable this would be nice.



> 
> > ------------------------------
> > AC_LIBTOOL_WIN32_DLL
> >     This macro should be used if the package has been ported to build
> clean
> > dlls on win32 platforms. Usually this means that any library data items
> are
> > exported with __declspec(dllexport) and imported with
> > __declspec(dllimport). If this macro is not used, libtool will assume that
> > the package libraries are not dll clean and will build only static
> > libraries on win32 hosts.
> >
> >     This macro must be called before AC_PROG_LIBTOOL, and provision must
> be
> > made to pass `-no-undefined' to libtool in link mode from the package
> > Makefile. Naturally, if you pass `-no-undefined', you must ensure that all
> > the library symbols really are defined at link time!
> > --------------------------------
> >
> 
> OK, I added the call to this macro.

Of course, this will break compiling on Cygwin until the libraries are actually
ported, but it's not like anyone is really USING gambas on cygwin yet, eh?

> 
> > Also, config.h doesn't appear to define USE_LTDL. 
> 
> It should ?

Grep the code for USE_LTDL.  Cygwin shared libs aren't named libfoo.0.0.3.so.
You need to open the .la on Cygwin, as it has a pointer to the "real" file.

Having an --enable-ltdl option for configure would be nice.

> 
> > I had to define this by 
> > hand to get gambas to look for .la's instead of .so's. (The actuall native
> > shared lib extenstion on cygwin is .dll.so, I think, although with the
> > stuff above and using LTDL everywhere, it should Just Work(tm).
> >
> > Making the libraries "cygwin ready" requires some header file magic. If
> > nobody is looking into the problem right
> > now, I think I might try to see exactly what needs to be done.
> 
> Can you be more explicit please ? What should I change ?
> 

It's more a concept, really.

Is there already a record of what a library exports, symbol wise?

Those symbols need to be declared with __declspec(dllexport) when the library is
being compiled, and __declspec(dllimport) when the library is being used. 
(Think of it as a really weird extern)

So, imagine this:

foo.h:
...
#ifdef _CYGWIN_
#ifdef FOO_C
#define magic __declspec(dllexport)
#else
#define magic __declspec(dllimport)
#endif
#else
#define magic
#endif

magic void thesymbol(void)

foo.c:
#define FOO_C
#include "foo.h"

void thesymbol()
{
  /* stuff */
}

bar.c:
#include "foo.h"

...

/* call thesymbol() */
thesymbol();

This example is oversimplified, but I hope you get the general idea.

It's easiest to do if you already know exactly what a library provides, and what
it uses.  You need to "forward import" all symbols a win32 shared library calls
directly. It's too stupid to think ahead.

Static libraries on Windows work similar to Unix.

Of course, static libraries are useless when you're trying to run gbi.

I think I'll see if I can get the SDL component ported to this paradigm.  If
that works OK, I'll write up some general guidelines of how this stuff works.

The main thing to do is make sure that library headers get passed a symbol that
they can use to tell if they're being used to compile the library, or using the
library. Having a libwhatever.c file for each library containing
#define LIBWHATEVER_COMPILE
#include "all_the_header_files_for_this_library"

would cause the dll import/export map to be dumped into libwhatever.o.

The big thing is keeping track of exactly what a library exports. (and imports,
but with -no-undefined, you'll catch that sooner, because it won't link.)


Actually, some newer ELF stuff is using a similar method, so having this system
in place would make it trivial to get Gambas working nicely on the new ELF
symbol versioning/hiding stuff. (Which is a pretty slick system -- smaller
libraries, less conflicts, better defined interfaces.)

> >
> > The QT frontend compiled fine for the kde-cygwin QT port, so no work to be
> > done there, at least. :)
> 
> Good news :-) There are X11 calls in the QT component, how are they solved ?
> 

X11 runs on Cygwin too. ;)

Yes, I am running X11 QT/Free on Windows. That's why it works.

I'm also contemplating writing a FOX toolkit frontend. I've got to have a
working Cygwin port first, though.

> >
> > Any concerns?
> >
> > --Brandon Bergren
> 
> Thanks for your patch, and talk about your work on the devel mailing-list. 
> Other people might be interested.

No problem. Roll back the -no-undefined part though, I have a feeling it will
break stuff on Unix.


> 
> Regards,
> 
> -- 
> Benoit Minisini
> mailto:gambas at ...1...

Thanks,

Brandon Bergren





More information about the Devel mailing list