Building library

anonymous via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Thu Aug 28 13:50:50 PDT 2014


On Thursday, 28 August 2014 at 19:29:40 UTC, papaboo wrote:
> My current file and module layout is
> test.d
> src/math/vector.d - module dragonfly.math.vector
> src/math/quaternion.d - module dragonfly.math.quaternion
>
> Compiling with
> $ dmd test.d src/math/vector.d src/math/quaternion.d && ./test
> works perfectly and runs the way I would expect.
>
> I then tried to compile a library as described
> http://ddili.org/ders/d.en/modules.html, so basically
> $ dmd src/math/vector.d src/math/quaternion.d -lib -ofmath -w
> $ dmd math.a test.d && ./test
>
> But this fails with the following error
> test.d(5): Error: module vector is in file
> 'dragonfly/math/vector.d' which cannot be read
>
> I realize I placed my files in a 'src' dir instead of
> 'dragonfly', but shouldn't explicitly declaring the module name
> in vector.d and quaternion.d fix that?

When you do `dmd math.a test.d`, you don't give dmd a file that
contains the module dragonfly.math.vector. math.a does contain
the object code, but it misses stuff like function signatures.
For this information dmd needs source files for each module.

If you change the directory structure to mirror the module
structure, dmd finds the necessary files itself.

Or you can specify all source files yourself on the command line,
along with the library file.

Since the library file already contains the object code, you can
also give dmd files that omit the function bodies. You may know
this concept from C: header files (.h). In D it's "interface
files" (.di).


More information about the Digitalmars-d-learn mailing list