Thread overview | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
March 25, 2013 [dmd-internals] Making druntime a shared library on linux | ||||
---|---|---|---|---|
| ||||
If you're making a D shared library, you'll need to use a shared library version of druntime for both the executable and your shared library. Otherwise, there will be two instances of druntime, and There Can Be Only One. I have 3 pull requests in to do this: https://github.com/D-Programming-Language/druntime/pull/462 https://github.com/D-Programming-Language/phobos/pull/1223 https://github.com/D-Programming-Language/dmd/pull/1798 What these do is: 1. build druntime as a shared library, need -defaultlib= to do that 2. split libdruntime.a off from libphobos2.a, so now the following flags must be passed to the link step: -lphobos2 -ldruntime 3. add the ability to link to the shared library version of druntime instead, with -shared-druntime flag to dmd: -lphobos2 -ldruntimeso I couldn't find a linker flag to prefer libdruntime.so over libdruntime.a, or vice versa, so I named the shared library libdruntimeso.so. Ugh. If there's a better way, please let me know. This is currently linux only, until we get things ironed out. If you want to try out the shared druntime, you'll need to set LD_LIBRARY_PATH. I set mine to: LD_LIBRARY_PATH=/home/walter/cbx/mars/phobos/generated/linux/64:/home/walter/cbx/mars/phobos/generated/linux/32 _______________________________________________ dmd-internals mailing list dmd-internals@puremagic.com http://lists.puremagic.com/mailman/listinfo/dmd-internals |
March 25, 2013 Re: [dmd-internals] Making druntime a shared library on linux | ||||
---|---|---|---|---|
| ||||
Posted in reply to Walter Bright | When all completed, we should make an article on the website out of this. Andrei On 3/25/13 3:46 PM, Walter Bright wrote: > If you're making a D shared library, you'll need to use a shared library > version of druntime for both the executable and your shared library. > Otherwise, there will be two instances of druntime, and There Can Be > Only One. > > I have 3 pull requests in to do this: > > https://github.com/D-Programming-Language/druntime/pull/462 > https://github.com/D-Programming-Language/phobos/pull/1223 > https://github.com/D-Programming-Language/dmd/pull/1798 > > What these do is: > > 1. build druntime as a shared library, need -defaultlib= to do that > > 2. split libdruntime.a off from libphobos2.a, so now the following flags > must be passed to the link step: > > -lphobos2 -ldruntime > > 3. add the ability to link to the shared library version of druntime > instead, with -shared-druntime flag to dmd: > > -lphobos2 -ldruntimeso > > I couldn't find a linker flag to prefer libdruntime.so over > libdruntime.a, or vice versa, so I named the shared library > libdruntimeso.so. Ugh. If there's a better way, please let me know. > > This is currently linux only, until we get things ironed out. > > If you want to try out the shared druntime, you'll need to set > LD_LIBRARY_PATH. I set mine to: > > LD_LIBRARY_PATH=/home/walter/cbx/mars/phobos/generated/linux/64:/home/walter/cbx/mars/phobos/generated/linux/32 > > _______________________________________________ > dmd-internals mailing list > dmd-internals@puremagic.com > http://lists.puremagic.com/mailman/listinfo/dmd-internals _______________________________________________ dmd-internals mailing list dmd-internals@puremagic.com http://lists.puremagic.com/mailman/listinfo/dmd-internals |
March 25, 2013 Re: [dmd-internals] Making druntime a shared library on linux | ||||
---|---|---|---|---|
| ||||
Posted in reply to Walter Bright | On Monday, March 25, 2013 12:46:46 Walter Bright wrote: > I couldn't find a linker flag to prefer libdruntime.so over libdruntime.a, or vice versa, so I named the shared library libdruntimeso.so. Ugh. If there's a better way, please let me know. I believe that the .so is preferred over the .a so that you normally give the .a version explicitly if you want to link against it, but it looks like there's also a -Bstatic flag to tell it to link against the static version. http://stackoverflow.com/questions/6578484/telling-gcc-directly-to-link-a-library-statically - Jonathan M Davis _______________________________________________ dmd-internals mailing list dmd-internals@puremagic.com http://lists.puremagic.com/mailman/listinfo/dmd-internals |
March 26, 2013 Re: [dmd-internals] Making druntime a shared library on linux | ||||
---|---|---|---|---|
| ||||
Posted in reply to Walter Bright | Walter Bright, el 25 de March a las 12:46 me escribiste: > If you're making a D shared library, you'll need to use a shared library version of druntime for both the executable and your shared library. Otherwise, there will be two instances of druntime, and There Can Be Only One. > > I have 3 pull requests in to do this: > > https://github.com/D-Programming-Language/druntime/pull/462 https://github.com/D-Programming-Language/phobos/pull/1223 https://github.com/D-Programming-Language/dmd/pull/1798 > > What these do is: > > 1. build druntime as a shared library, need -defaultlib= to do that > > 2. split libdruntime.a off from libphobos2.a, so now the following flags must be passed to the link step: > > -lphobos2 -ldruntime > > 3. add the ability to link to the shared library version of druntime instead, with -shared-druntime flag to dmd: > > -lphobos2 -ldruntimeso > > I couldn't find a linker flag to prefer libdruntime.so over libdruntime.a, or vice versa, so I named the shared library libdruntimeso.so. Ugh. If there's a better way, please let me know. ld will always pick the shared one when available. To force using the static one the only way I know is to pass it as another file to the linker instead of using -ldruntime (or using -static but that makes the whole program be statically linked). -- Leandro Lucarella (AKA luca) http://llucax.com.ar/ ---------------------------------------------------------------------- GPG Key: 5F5A8D05 (F8CD F9A7 BF00 5431 4145 104C 949E BFB6 5F5A 8D05) ---------------------------------------------------------------------- Wenn ist das nunstück git und slotermeyer? Ja! Beiherhund das oder die Flipperwaldt gersput! -- Monty Python (no leer si sabés alemán) _______________________________________________ dmd-internals mailing list dmd-internals@puremagic.com http://lists.puremagic.com/mailman/listinfo/dmd-internals |
March 25, 2013 Re: [dmd-internals] Making druntime a shared library on linux | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jonathan M Davis | On 3/25/2013 3:19 PM, Jonathan M Davis wrote: > On Monday, March 25, 2013 12:46:46 Walter Bright wrote: >> I couldn't find a linker flag to prefer libdruntime.so over libdruntime.a, >> or vice versa, so I named the shared library libdruntimeso.so. Ugh. If >> there's a better way, please let me know. > I believe that the .so is preferred over the .a so that you normally give the > .a version explicitly if you want to link against it, Tried that (giving a .so or .a explicit extension). Doesn't work, it just gives an error. > but it looks like > there's also a -Bstatic flag to tell it to link against the static version. will look into that. > > http://stackoverflow.com/questions/6578484/telling-gcc-directly-to-link-a-library-statically > > _______________________________________________ dmd-internals mailing list dmd-internals@puremagic.com http://lists.puremagic.com/mailman/listinfo/dmd-internals |
March 25, 2013 Re: [dmd-internals] Making druntime a shared library on linux | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jonathan M Davis | On 3/25/2013 3:19 PM, Jonathan M Davis wrote: > On Monday, March 25, 2013 12:46:46 Walter Bright wrote: >> I couldn't find a linker flag to prefer libdruntime.so over libdruntime.a, >> or vice versa, so I named the shared library libdruntimeso.so. Ugh. If >> there's a better way, please let me know. > I believe that the .so is preferred over the .a so that you normally give the > .a version explicitly if you want to link against it, but it looks like > there's also a -Bstatic flag to tell it to link against the static version. > > http://stackoverflow.com/questions/6578484/telling-gcc-directly-to-link-a-library-statically -Bstatic doesn't seem to be very well documented or implemented in general. http://gcc.gnu.org/onlinedocs/gcc-4.8.0/gcc/VxWorks-Options.html#VxWorks-Options _______________________________________________ dmd-internals mailing list dmd-internals@puremagic.com http://lists.puremagic.com/mailman/listinfo/dmd-internals |
March 25, 2013 Re: [dmd-internals] Making druntime a shared library on linux | ||||
---|---|---|---|---|
| ||||
Posted in reply to Walter Bright | On Mon, Mar 25, 2013 at 04:46:12PM -0700, Walter Bright wrote: > > On 3/25/2013 3:19 PM, Jonathan M Davis wrote: > >On Monday, March 25, 2013 12:46:46 Walter Bright wrote: > >>I couldn't find a linker flag to prefer libdruntime.so over libdruntime.a, or vice versa, so I named the shared library libdruntimeso.so. Ugh. If there's a better way, please let me know. > >I believe that the .so is preferred over the .a so that you normally give the .a version explicitly if you want to link against it, > > Tried that (giving a .so or .a explicit extension). Doesn't work, it > just gives an error. [...] AFAIK, if you're giving an explicit extension, you have to specify the filename instead of -l<name>, something like: ld -oexecutable program.o libabc.so Assuming you have library paths setup correctly (or have requisite -L flags), using -l should prefer .so over .a: ld -oexecutable program.o -labc (should link in libabc.so, assuming both libabc.so and libabc.a are found in the library paths) T -- Frank disagreement binds closer than feigned agreement. _______________________________________________ dmd-internals mailing list dmd-internals@puremagic.com http://lists.puremagic.com/mailman/listinfo/dmd-internals |
March 25, 2013 Re: [dmd-internals] Making druntime a shared library on linux | ||||
---|---|---|---|---|
| ||||
Posted in reply to H. S. Teoh | On Mon, Mar 25, 2013 at 04:49:00PM -0700, H. S. Teoh wrote: > On Mon, Mar 25, 2013 at 04:46:12PM -0700, Walter Bright wrote: > > > > On 3/25/2013 3:19 PM, Jonathan M Davis wrote: > > >On Monday, March 25, 2013 12:46:46 Walter Bright wrote: > > >>I couldn't find a linker flag to prefer libdruntime.so over libdruntime.a, or vice versa, so I named the shared library libdruntimeso.so. Ugh. If there's a better way, please let me know. > > >I believe that the .so is preferred over the .a so that you normally give the .a version explicitly if you want to link against it, > > > > Tried that (giving a .so or .a explicit extension). Doesn't work, it > > just gives an error. > [...] > > AFAIK, if you're giving an explicit extension, you have to specify the filename instead of -l<name>, something like: > > ld -oexecutable program.o libabc.so > > Assuming you have library paths setup correctly (or have requisite -L flags), using -l should prefer .so over .a: > > ld -oexecutable program.o -labc > (should link in libabc.so, assuming both libabc.so and libabc.a > are found in the library paths) [...] Actually, scratch that. According to ld's manpage, using -l *always* links with the .a. My bad. T -- Talk is cheap. Whining is actually free. -- Lars Wirzenius _______________________________________________ dmd-internals mailing list dmd-internals@puremagic.com http://lists.puremagic.com/mailman/listinfo/dmd-internals |
Copyright © 1999-2021 by the D Language Foundation