Ubuntu dmd 2.065 amd64 linkage problem.

Carl Sturtivant sturtivant at gmail.com
Sun Mar 16 13:46:07 PDT 2014


> DMD started to support shared lib on linux from 2.063.
> This may be useful: http://dlang.org/dll-linux.html
> Also note that if you are only writting the shared lib and not 
> the client, it would be easyier to bootstrap it using gcc's 
> attributes (see 
> http://stackoverflow.com/questions/9759880/automatically-executed-functions-when-loading-shared-libraries 
> ).
> Else, there is a Runtime.loadLibrary (which will be improved 
> later), to load and start a D shared library (if you just 
> dlopen, static ctor & stuff won't be initialized).

Thanks for all that information. I did some work, and formed the 
following conclusions.

I can now confirm that the part of the document
http://dlang.org/dll-linux.html
about loading D dynamic libraries from a D main program is 
experimentally apparently correct with a real world largish 
executable.

The machinery to initialize the runtime in the dynamic library in
http://stackoverflow.com/questions/9759880/automatically-executed-functions-when-loading-shared-libraries
is apparently unnecessary in this case, though I have seen some 
hints it may be necessary when having a C main program load a D 
dynamic library.

If you want a D dynamic library to call-back functions in the D 
main program that loaded it, you may need to supply the linker 
with the -export-dynamic flag (on the dmd command line with 
-L-export-dynamic ) so as to expose symbols in the main program 
for automatic linkage to the dynamic library at the point it is 
loaded. This worked nicely for me.


More information about the Digitalmars-d-learn mailing list