www.digitalmars.com         C & C++   DMDScript  

D.gnu - Mingw GDC, Dll's & Phobos

reply Venix <venix1 hotmail.com> writes:
For a project I'm working on I wanted to use dll's.  DMD was lacking 
support. So I switched to GDC.

After some work and testing I managed to give dll support to GDC.

I've included a patch for gdc to allow it to support dll's.  I also got 
phobos to work as a dll. I've used it for about a month now and as of 
yet there are no side effects.

There is one flaw in the phobos.dll design.  If you use DllMain for your 
dlls and they are linked to a program with a library. Then the garbage 
collector will not exist at that time. I personally ain't found this an 
issue yet. But I haven't used Static constructors and the such.
Jan 06 2006
next sibling parent reply "Charles" <noone nowhere.com> writes:
I would love to see a GDC/Mingwn package on windows that comes with an
installer , some libs etc ... can you post your binary somewhere ?  Or where
can I find instructions on building gdc on windows with mingw ?


Thanks,
Charlie


"Venix" <venix1 hotmail.com> wrote in message
news:dpmvf2$208o$2 digitaldaemon.com...
 For a project I'm working on I wanted to use dll's.  DMD was lacking
 support. So I switched to GDC.

 After some work and testing I managed to give dll support to GDC.

 I've included a patch for gdc to allow it to support dll's.  I also got
 phobos to work as a dll. I've used it for about a month now and as of
 yet there are no side effects.

 There is one flaw in the phobos.dll design.  If you use DllMain for your
 dlls and they are linked to a program with a library. Then the garbage
 collector will not exist at that time. I personally ain't found this an
 issue yet. But I haven't used Static constructors and the such.
---------------------------------------------------------------------------- ----


 rm -f *.o *.dll temp.a static.a lib/*.o lib/*.a lib/*.dll
 cp ../libgphobos.a .

 #Explode Static library
 ar x libgphobos.a

 #Grab Duplicate names
 ar xN 1 libgphobos.a zlib.o
 mv zlib.o zlib_d.o
 ar xN 2 libgphobos.a zlib.o

 #Grab Duplicate names
 ar xN 1 libgphobos.a crc32.o
 mv crc32.o crc_32_d.o
 ar xN 2 libgphobos.a crc32.o

 #Grab Duplicate names
 ar xN 1 libgphobos.a syserror.o
 mv syserror.o syserror_d.o
 ar xN 2 libgphobos.a syserror.o

 mkdir -p lib

 #Remove static only items
 mv cmain.o      lib/_cmain.o
 mv rundmain.o   lib/_rundmain.o
 mv dgccmain2.o  lib/_dgccmain2.o
 mv moduleinit.o lib/_moduleinit.o
 mv object.o     lib/_object.o

 #Build Temp lib
 ar r static.a lib/*.o

 #Build DLL
 gcc -shared -Wl,--export-all-symbols -o
gphobos.dll -Wl,--out-implib=temp.a *.o -lstdc++ -lws2_32 -luuid static.a
 cp gphobos.dll /mingw/bin

 cd lib

 #Extract DLL Library so we only need one phobos library
 ar x ../temp.a
 ar r libgphobos.a *.o
 cd ..

 cp lib/libgphobos.a ../lib
Jan 07 2006
parent "Charles" <noone nowhere.com> writes:
Actually GDC built without a problem with cygwin and gcc 3.4.5 :).

Charlie


"Charles" <noone nowhere.com> wrote in message
news:dposb7$11c8$1 digitaldaemon.com...
 I would love to see a GDC/Mingwn package on windows that comes with an
 installer , some libs etc ... can you post your binary somewhere ?  Or
where
 can I find instructions on building gdc on windows with mingw ?


 Thanks,
 Charlie


 "Venix" <venix1 hotmail.com> wrote in message
 news:dpmvf2$208o$2 digitaldaemon.com...
 For a project I'm working on I wanted to use dll's.  DMD was lacking
 support. So I switched to GDC.

 After some work and testing I managed to give dll support to GDC.

 I've included a patch for gdc to allow it to support dll's.  I also got
 phobos to work as a dll. I've used it for about a month now and as of
 yet there are no side effects.

 There is one flaw in the phobos.dll design.  If you use DllMain for your
 dlls and they are linked to a program with a library. Then the garbage
 collector will not exist at that time. I personally ain't found this an
 issue yet. But I haven't used Static constructors and the such.
--------------------------------------------------------------------------
--
 ----




 rm -f *.o *.dll temp.a static.a lib/*.o lib/*.a lib/*.dll
 cp ../libgphobos.a .

 #Explode Static library
 ar x libgphobos.a

 #Grab Duplicate names
 ar xN 1 libgphobos.a zlib.o
 mv zlib.o zlib_d.o
 ar xN 2 libgphobos.a zlib.o

 #Grab Duplicate names
 ar xN 1 libgphobos.a crc32.o
 mv crc32.o crc_32_d.o
 ar xN 2 libgphobos.a crc32.o

 #Grab Duplicate names
 ar xN 1 libgphobos.a syserror.o
 mv syserror.o syserror_d.o
 ar xN 2 libgphobos.a syserror.o

 mkdir -p lib

 #Remove static only items
 mv cmain.o      lib/_cmain.o
 mv rundmain.o   lib/_rundmain.o
 mv dgccmain2.o  lib/_dgccmain2.o
 mv moduleinit.o lib/_moduleinit.o
 mv object.o     lib/_object.o

 #Build Temp lib
 ar r static.a lib/*.o

 #Build DLL
 gcc -shared -Wl,--export-all-symbols -o
gphobos.dll -Wl,--out-implib=temp.a *.o -lstdc++ -lws2_32 -luuid static.a
 cp gphobos.dll /mingw/bin

 cd lib

 #Extract DLL Library so we only need one phobos library
 ar x ../temp.a
 ar r libgphobos.a *.o
 cd ..

 cp lib/libgphobos.a ../lib
Jan 08 2006
prev sibling parent Venix <venix1 hotmail.com> writes:
Recently, I started working with D again. It didn't take me long to 
discover another bug with my phobos dll.  The issue I found is related 
to garbage collecting. What happens is that memory I've allocated got 
trashed whenever it ran.  This was because scanStaticData was part of 
the phobos dll and only looked at it's static section.  I have modified 
parts of phobos to fix this. I removed scanStaticData from the gc files 
and put it into dgccmain2.d.  This way custom dlls can call 
scanStaticData(); and register their own static data.  Based on the 
examples given by walter on how to make a dll use a single gc. I belive 
that should prevent the GC issue.

Other potential issues:
- moduleinit.o is not dynamically linked.  This is becuase dlls need to 
call _moduleCtor upon loading.  By dynamically linking it. Such function 
calls cause all other Module Contrustors to rerun.
- object.o is not dynmically linked.  I belive it should be. But doing 
so causes Access Violations when loading dlls of some complexity.  So 
far I haven't come across any serious repercussions.

Included is the script I use to make the dll and a patch to give 
gcc-3.4.5 (Mingw) dll support.  This patch does the same as the previos 
one I offered. So its unnecessary to run the previous one.

Mingw:
   Download 3.4.5 sources.  Extract gdc files. Patch.
   apply my patch. patch -p0 < gdc_dll.patch Should work.
   run ./gcc-3.4.5-build.sh
Apr 25 2006