Dynamically calling external libraries.

Marc Schütz" <schuetzm at gmx.net> Marc Schütz" <schuetzm at gmx.net>
Thu Feb 27 12:57:27 PST 2014


On Thursday, 27 February 2014 at 14:38:11 UTC, Setra wrote:
> I am compiling it the way to guide recomends it. It compiles 
> however for some reason when it runs the value returned by the 
> dll is incorrect? Does anyone know why? It always returns the 
> same value even when I change the parameter.

What do you mean by "returns"? You're not actually printing the 
return value of fn(). Are you referring to the value printed in 
dll()?

For me this works (openSUSE 13.1, DMD git master):
# dmd main1.d -L-ldl
# dmd -c dll.d -fPIC
# dmd -oflibdll.so dll.o -shared -defaultlib=
# LD_LIBRARY_PATH=. ./main1
+main()
libdll.so is loaded
dll() function is found
dll()
72
unloading libdll.so
-main()

(I had to remove the "import std.stdio" and change the writeln() 
to printf("%d", x) to get it to link because of an undefined 
symbol.)


More information about the Digitalmars-d-learn mailing list