On Thursday, 26 January 2012 at 22:10:23 UTC, Justin Whear wrote:
If you want your Array code to be a separate library/project, you can compile it like so:
dmd Array.d -lib

Then when you compile your other project:
dmd prd.d -I/location/of/Array.d -L/location/of/Array.so

Justin

It is actually a little more than that.

dmd array.d -lib -oflibarray.a

dmd does no currently generate shared libraries, so .a (archive) is used.

dmd prd.d -I. -L-L. -L-larray

-I (Include directory, used by compiler for locating "header" files. These are used by the compiler to verify the calls you are making into the library, and to generate code from templates if those are being used)

-L-L (Pass to the linker the flag -L. The ld linker flag -L is for the library search path)

-L-l (Pass the linker the flag -l. The ld linker flag -l request that a library be linked)

Libraries are named starting with lib by Unix convention. When passing the library name this is left off (-lm load libm.so or libm.a). I believe you can leave it on though (-llibm) but am not sure.

The reason DMD does not compile imported libraries is because of two reasons. When the magic stops working you still have to deal with and understand these steps. The compiler is busy with its job of converting code, it should be helping other tools to make its job simple ("Compiler as a Service"). You will find rdmd is distributed with dmd:

rdmd prd.d

Reply via email to