Using Libraries

rikki cattermole via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Tue Sep 20 08:07:53 PDT 2016


On 21/09/2016 3:01 AM, Darren wrote:
> Hey, all
>
> I keep hitting roadblocks and that's mainly due to not knowing how to
> include libraries.  So far I've been getting by with downloading .dll's
> and including the necessary dependencies in the dub.json file and having
> that build/run my project.  I'm sure I'm making a mess of that, too, but
> it works and now I need to learn how to include static libraries (and
> probably understand github and other dub features).
>
> Right now, for example, I want to use the gl3n package:
> https://github.com/Dav1dde/gl3n
>
> What do I need in order to build libraries, and have dub include them
> when I import modules?   Can I keep all of the libraries in one place so
> I'm not copy-pasting them (like in lib and bin folders that I keep seeing)?
>
> As you can tell, I'm still very new to all of this and I have no idea
> where to start.  Thank you for your time!

Ok lets start at the very beginning with straight dmd.

You have a total of two things you can pass in, an import directory and 
source files.
Source files are compiled in and import directories are basically a way 
to tell the compiler that certain symbols can exist but it won't create 
them.

Now from this you abstract away into dependencies such as packages / 
subpackages.
This is where dub comes in, it will fetch (known) projects with dub 
definition files (dub.json/sdl), place them into a folder under your 
profile directory and allow you to build against them and automatically 
provide them as import directories as required.

So how do you do that? Simple.

"dependencies": {
	"mypackage": ">=0.0.0"
}

Inside of a dub.json file (sdl is a little different check 
code.dlang.org for more help on the subject).


More information about the Digitalmars-d-learn mailing list