How would you develop a library in D language?
I want to write a simple library for image processing that I then want to use in an application.
I am looking for analogy to either Java's JARs with Maven system (build, install, use in other projects) or any other package management tool.
What I'd like to know is
I'm asking this because I don't have the intuition I do in Java or C++.
So what's the story with D?
I am using Visual-D to develop the code, but I have DUB installed as well.
The generally accepted way is to use dub, a package manager for D.
There is a good collection of dub packages available already: http://code.dlang.org/
Another way would be to simply publish your package as a git repository, then use it as a git submodule. This is the approach I've been using for my libraries.
You can do this with dub by setting target type but i will show another way.
By using MakefileForD,
Why ?
Because dub install lib and bin into ~/.dub
. And is not possible to install to a shared dir.
As example Linux Filesystem Hierarchy Standard tell that binaries should to go to /usr/bin
.
You can't respect this standard by using dub.
Shared lib with Makefile ,
Create a project
myproject
└── src
└── myproject
Install Makefile_lib into root directory and rename it to Makefile.
Install command.make into root directory
You have now
myproject
├── command.make
├── Makefile
└── src
└── myproject
└── main.d
Set source dir
At 5th line from Makefile file
export REPO_SRC_DIR = src
Build
all you have to do now is:
make DC=dmd shared-lib
DC accept dmd ldc and gdc compiler
Install
make install
setting custom install directory
make install PREFIX=/usr LIB_DIR=/usr/lib64
For binaries that is same only instead to take Makefile_lib you need to take Makefile_exe
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With