www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Building library

reply "papaboo" <asgerhoedt gmail.com> writes:
Hey

I've just started getting into D and so far I'm just messing
around with it in a small math library.
However I've run into an issue while trying to build a library
and linking it with my main file.

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?

I'm compiling with dmd v 2.065

Hope someone has an answer for me so I can continue experimenting
with D.
Aug 28 2014
next sibling parent "Cassio Butrico" <cassio_butrico ig.com.br> writes:
On Thursday, 28 August 2014 at 19:29:40 UTC, papaboo wrote:
 Hey

 I've just started getting into D and so far I'm just messing
 around with it in a small math library.
 However I've run into an issue while trying to build a library
 and linking it with my main file.

 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?

 I'm compiling with dmd v 2.065

 Hope someone has an answer for me so I can continue 
 experimenting
 with D.
try in vector.d type in fist line. module src.math.vetor; in quaternion.d module src.math.quaternion; save e compile.
Aug 28 2014
prev sibling next sibling parent "anonymous" <anonymous example.com> writes:
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).
Aug 28 2014
prev sibling parent reply "yazd" <yazan.dabain gmail.com> writes:
On Thursday, 28 August 2014 at 19:29:40 UTC, papaboo wrote:
 Hey

 I've just started getting into D and so far I'm just messing
 around with it in a small math library.
 However I've run into an issue while trying to build a library
 and linking it with my main file.

 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?

 I'm compiling with dmd v 2.065

 Hope someone has an answer for me so I can continue 
 experimenting
 with D.
When compiling test.d, the compiler needs to find the function signatures/struct declarations and so on that rely on the other modules. To do that, you have to include the other modules for the compiler to read. You can do that by: dmd test.d math.a -Isrc && ./test When you are using -I flag, the included files are NOT compiled, but can be thought of as being used as headers in C/C++. One other note, note that you should include 'src' folder, and the files would be found properly using the module -> filesystem mapping.
Aug 29 2014
parent "papaboo" <asgerhoedt gmail.com> writes:
On Friday, 29 August 2014 at 09:02:05 UTC, yazd wrote:
 On Thursday, 28 August 2014 at 19:29:40 UTC, papaboo wrote:
 Hey

 I've just started getting into D and so far I'm just messing
 around with it in a small math library.
 However I've run into an issue while trying to build a library
 and linking it with my main file.

 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?

 I'm compiling with dmd v 2.065

 Hope someone has an answer for me so I can continue 
 experimenting
 with D.
When compiling test.d, the compiler needs to find the function signatures/struct declarations and so on that rely on the other modules. To do that, you have to include the other modules for the compiler to read. You can do that by: dmd test.d math.a -Isrc && ./test When you are using -I flag, the included files are NOT compiled, but can be thought of as being used as headers in C/C++. One other note, note that you should include 'src' folder, and the files would be found properly using the module -> filesystem mapping.
Thanks for the answers everyone. The -I flag comes closest to solving the issue. Ideally I would like to be able to alias my src folder to dragonfly in the module system while compiling smaller libs. But if that's not possible then adding a dragonfly folder to src and using -Isrc to point the compiler towards the right folders will work just fine. Off to play with libraries. :)
Aug 29 2014