DLL's and Objective C

Mikey jeffdbREMOVETHIS@goodnet.com
Sat Apr 11 15:31:00 GMT 1998

Objective c dll's should certainly be possible,
If you are using B19 this should be all you need

if you are using B18 search for 
Initialising gnuwin DLLs
in the Mailing list

>> if linking against the original B18 cygwin.dll/libcygwin.a you MUST
>> give a --image-base other than 0x10000000 even to relocatable
>> dll's, B18's cygwin.dll won't get relocated under win95 NO MATTER WHAT.

First you need to read up on building dll's in general.

The most important thing is that dll's have an entry point
that is called by the OS, and that must return 1 , like

#define APIENTRY __stdcall

/*  PURPOSE:  DllMain is called by Windows when
             the DLL is initialized, Thread Attached, and other times.
             Refer to SDK documentation, as to the different ways this
             may be called.
             The DllMain function should perform additional initialization
             tasks required by the DLL.  In this example, no initialization
             tasks are required.  DllMain should return a value of 1 if
             the initialization is successful.

BOOL APIENTRY DllMain(HANDLE hInst, DWORD ul_reason_being_called, LPVOID lpReserved)
    return 1;

Now for the runtime initialization of the cygwin32 layer you must
include 2 extra object files, produced from the following c files

cut here -------------------------------------------------

/* _DllMainCRTStartup.c initialize the c runtime
layer setting the stdio pointers to the correct values
and returning to the OS, compile with
gcc -c _DllMainCRTStartup.c
include in the dll with 
-e __DllMainCRTStartup		on the link line. */

#include <stdio.h>
extern struct _reent *_imp__reent_data;

int DllMain(int, int, void *);

int _DllMainCRTStartup(int handle, int reason, void *ptr)
{ _impure_ptr=_imp__reent_data; return DllMain(handle, reason, ptr); }

cut here -----------------------------------------------
/* dll_reent.c a fake _impure_ptr to avoid
linking in the real one in libccrt0.cc which dosen't work
for dll's. Compile with 
gcc -c dll_reent.c
include in the dll explicitly on the link command line
gcc  -o my.dll dll_reent.o *.o -mwindows -Wl,--dll,-e,__DllMainCRTStartup 
ld -o my.dll dll_reent.o *.o --subsystem windows   -lcygwin32 -lkernel32 --dll -e __DllMainCRTStartup
#ifdef __CYGWIN32__
void *_impure_ptr;
cut here --------------------------------------

to call functions in a dll you can just declare them as usual

to reference data in a dll you must call through the pointer
to the data, NOT the function thunk, like this

char **argc;

in an executable linking to a lib becomes

char **_imp__argc
#define __argc (*_imp__argc)

when linking to a dll

How all of this would translate to objective c, I don't know
but these are the points that most people have problems
with when creating their own new cygwin32 dll's.

On Tue, 7 Apr 1998 11:00:11 +0200 (MET DST), you wrote:

>I have been trying to build dll's in the cygwin32 environment. In
>itself this works OK! (Great work). I have, however, one question. I
>have build my own version of the compiler (gcc 2.8.1), which has an
>option to build the objective-c runtime as a dll. Should this still
>work? I cannot get it to build.
>Furthermore, I am trying to build a dll with objective-c objects. Does
>anybody have any exprerience with that? I cannot get it to build
>one. Is there any work in that area, or am I trying something
>Any help/comments/info is appreciated.
>    Ronald Pijnacker.
>    rhp@iname.com
>For help on using this list (especially unsubscribing), send a message to
>"gnu-win32-request@cygnus.com" with one line of text: "help".

Linux a platform built by, and for users, standing on
the firm legs of reliability, and speed.

Microsoft Windows, a platform without a leg to stand on.

delete REMOVETHIS from the above to reply
For help on using this list (especially unsubscribing), send a message to
"gnu-win32-request@cygnus.com" with one line of text: "help".

More information about the Cygwin mailing list