digitalmars.D - Easily building a dynamic library with DMD
- Jacob Carlborg (22/22) Apr 06 2010 Since I made modifications to Tango to work as a dynamic library on Mac
- Michel Fortin (14/19) Apr 06 2010 This prompted me to check how creating a dynamic library is handled by
Since I made modifications to Tango to work as a dynamic library on Mac OS X I would now like DMD to be able to easily build dynamic libraries. Building a dynamic library on Mac OS X with GCC is done like this: gcc -dynamiclib files -o libdynamic.dylib Trying to do the same with DMD causes some problems: First try: using dmd and passing -dynamiclib to the linker. This will fail since -dynamiclib is a gcc specific flag and not a linker flag. When using the -dynamiclib flag the library is built with libtool and not ld. Second try: building with dmd and then linking with gcc. This will cause the problem that I have to link to the D standard library when linking with gcc and for that I have to know the path to the standard library. I don't know if it is possible to get the path to the standard library. I see three different solutions to this: 1. Add a -dylib flag, or similar, to dmd that will compile a dynamic library. 2. Make it possible to pass flags to gcc and not just the linker with dmd. 3. Make it possible to get the path to the standard library with dmd. The first option is the preferred option. What do you think? Any other suggestions to solve the problem? /Jacob Carlborg
Apr 06 2010
On 2010-04-06 06:26:01 -0400, Jacob Carlborg <doob me.com> said:Second try: building with dmd and then linking with gcc. This will cause the problem that I have to link to the D standard library when linking with gcc and for that I have to know the path to the standard library. I don't know if it is possible to get the path to the standard library.This prompted me to check how creating a dynamic library is handled by D for Xcode. D for Xcode does this exact thing you describe: use GCC for linking (because Xcode expects gcc when converting build settings to command line arguments). So I added a dynamic library target to a project to check if it worked all right, and it does! It's great to see a feature like this (creating a dynamic library) work without having tested it before. :-) Perhaps I need to add a project template for dynamic libraries so you can save the few clicks it takes to create the target. -- Michel Fortin michel.fortin michelf.com http://michelf.com/
Apr 06 2010