Using Libraries

Karabuta via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Tue Sep 20 12:45:57 PDT 2016


On Tuesday, 20 September 2016 at 15:38:55 UTC, Darren wrote:
> On Tuesday, 20 September 2016 at 15:07:53 UTC, rikki cattermole 
> wrote:
>
>> Ok lets start at the very beginning...
>
> I think I need to start before that, haha.
>
> I might need more of a step-by-step guide.  I'm a complete 
> beginner to programming, not just D.  I worked through 
> Programming in D, where I was just compiling with dmd, then 
> when I decided to learn OpenGL I seem to be using dub for 
> everything.
>
> There have been a few libraries I've wanted to use but couldn't 
> because they didn't have a pre-compiled binary, which is all 
> I've been able to get working through sheer trial and error.  
> Some sites say to use things like CMake and cygwin, but I'm 
> uncomfortable using things I have no idea about.

Dub is like a package manager for D (like what npm is to 
node.js). All dub libraries are hosted at code.dlang.org. When 
you see a library at code.dlang.org you want to use, you could 
either type "dub install packagename" whilst in the dub project 
ROOT or specify dependencies in the dub.json file.
You can then run "dub run" which will take care of fetching and 
building dependencies/libraries from code.dlang.org (including 
linking and running the binary).

For example, there is a web framework called vibe.d. If I want to 
use vide.d, I can specify dependencies as;

dependencies: {
     "vide-d":"^0.7.29"
}


In my app.d file (which is available for any dub project created 
using "dub init projectname") I can import vibe.d using;

import vide.d;
void main() {
...
}

I can now compile and run the program with "dub run" or "dub 
build" to only build and link without running.



More information about the Digitalmars-d-learn mailing list