www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - undefined reference to `rt_loadLibrary'

reply Jean-Louis Leroy <jl leroy.nyc> writes:
Hello,

I am trying to dynamically load a shared object using 
core.runtime.Runtime.loadLibrary. The link fails with a undefined 
reference to `rt_loadLibrary' error. Indeed when I `nm 
/usr/lib/x86_64-linux-gnu/libphobos2.a` I don't see it there. Is 
an extra lib needed?

dub -v output:

openmethods:dynaload 0.0.9+commit.3.g6bc05eb: building 
configuration "application"...
dmd -c 
-ofexamples/dynaload/.dub/build/application-debug-linux.posix-x86_64-dmd_2075-F869A096DE167CDA3C339619B5A0C758/op
nmethods_dynaload.o -debug -g -w -version=Have_openmethods_dynaload
-version=Have_openmethods -version=Have_openmethods_dynalib
-Iexamples/dynaload/source/ -Isource/ -Iexamples/dynalib/source/
examples/dynaload/source/app.d -vcolumns
Linking...
dmd 
-ofexamples/dynaload/.dub/build/application-debug-linux.posix-x86_64-dmd_2075-F869A096DE167CDA3C339619B5A0C758/
penmethods_dynaload examples/dynaload/.dub/build/application-debug-linux.posix-x86_64-dmd_2075-F869A096DE167CDA3C339619B5A0C758/op
nmethods_dynaload.o examples/dynalib/.dub/build/library-debug-linux.posix-x86_64-dmd_2075-A1AE604B4B5F4B4357215CE03CBCA526/libo
enmethods_dynalib.a .dub/build/library-debug-linux.posix-x86_64-dmd_2075-906C07C721DFE17599071D69E200C
C8/libopenmethods.a -L--no-as-needed -g
examples/dynaload/.dub/build/application-debug-linux.posix-x86_64-dmd_2075-F869A096DE167CDA3C339619B5A0C758/ope
methods_dynaload.o: In function
`_D4core7runtime7Runtime17__T11loadLibraryZ11loadLibraryFxAaZPv':
/usr/include/dmd/druntime/import/core/runtime.d:222: undefined 
reference to `rt_loadLibrary'
collect2: error: ld returned 1 exit status
Jul 30
parent Jean-Louis Leroy <jl leroy.nyc> writes:
On Sunday, 30 July 2017 at 16:44:52 UTC, Jean-Louis Leroy wrote:
 Hello,

 I am trying to dynamically load a shared object using 
 core.runtime.Runtime.loadLibrary. The link fails with a 
 undefined reference to `rt_loadLibrary' error. Indeed when I 
 `nm /usr/lib/x86_64-linux-gnu/libphobos2.a` I don't see it 
 there. Is an extra lib needed?

 [...]
OK after more googling I found that adding `dflags "-defaultlib=phobos2` to my dub.sdl file solves this problem.
Jul 30