www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - libphobos.so and loading libraries at runtime

reply "FreeSlave" <freeslave93 gmail.com> writes:
import core.runtime;

int main()
{
     Runtime.loadLibrary("does not care");
     Runtime.unloadLibrary(null);
     return 0;
}

When I try to compile this code with 'dmd main.d', I get errors

main.o: In function 
`_D4core7runtime7Runtime17__T11loadLibraryZ11loadLibraryFxAaZPv':
main.d:(.text._D4core7runtime7Runtime17__T11loadLibraryZ11loadL
braryFxAaZPv+0x4d): 
undefined reference to `rt_loadLibrary'
main.o: In function 
`_D4core7runtime7Runtime19__T13unloadLibraryZ13unloadLibraryFPvZb':
main.d:(.text._D4core7runtime7Runtime19__T13unloadLibraryZ13unlo
dLibraryFPvZb+0x8): 
undefined reference to `rt_unloadLibrary'

But it's built without errors when I separate compile and link 
parts:
dmd -c main.d
gcc main.o -lphobos2 -o main

I checked libraries with nm utility and actually found no such 
symbols in static version of libphobos. But shared one has these 
symbols.

Well, I'm aware of that runtime loading requires shared version 
of phobos2 to avoid duplicating of D runtime. But why does dmd 
use static linking by default? Is shared version of phobos still 
experimental? Anyway we need some remarks in documentation about 
the lack of these functions in static version of phobos.
Jan 05 2014
next sibling parent "Sean Kelly" <sean invisibleduck.org> writes:
On Sunday, 5 January 2014 at 20:47:44 UTC, FreeSlave wrote:
 import core.runtime;

 int main()
 {
     Runtime.loadLibrary("does not care");
     Runtime.unloadLibrary(null);
     return 0;
 }

 When I try to compile this code with 'dmd main.d', I get errors

 main.o: In function 
 `_D4core7runtime7Runtime17__T11loadLibraryZ11loadLibraryFxAaZPv':
 main.d:(.text._D4core7runtime7Runtime17__T11loadLibraryZ11loadL
braryFxAaZPv+0x4d): 
 undefined reference to `rt_loadLibrary'
 main.o: In function 
 `_D4core7runtime7Runtime19__T13unloadLibraryZ13unloadLibraryFPvZb':
 main.d:(.text._D4core7runtime7Runtime19__T13unloadLibraryZ13unlo
dLibraryFPvZb+0x8): 
 undefined reference to `rt_unloadLibrary'

 But it's built without errors when I separate compile and link 
 parts:
 dmd -c main.d
 gcc main.o -lphobos2 -o main

 I checked libraries with nm utility and actually found no such 
 symbols in static version of libphobos. But shared one has 
 these symbols.

 Well, I'm aware of that runtime loading requires shared version 
 of phobos2 to avoid duplicating of D runtime. But why does dmd 
 use static linking by default? Is shared version of phobos 
 still experimental? Anyway we need some remarks in 
 documentation about the lack of these functions in static 
 version of phobos.
This seems like a weird change if intentional, since the function is publicly declared. I'd file a bug report.
Jan 07 2014
prev sibling parent "Dicebot" <public dicebot.lv> writes:
On Sunday, 5 January 2014 at 20:47:44 UTC, FreeSlave wrote:
 But why does dmd use static linking by default? Is shared 
 version of phobos still experimental?
It is. It works pretty good in practice but Martin wanted to improve provided utilities for library/symbol loading before announcing it as released AFAIR.
Jan 07 2014