www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Using Libraries

reply Darren <darren.fielding hotmail.co.uk> writes:
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!
Sep 20 2016
parent reply rikki cattermole <rikki cattermole.co.nz> writes:
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).
Sep 20 2016
parent reply Darren <darren.fielding hotmail.co.uk> writes:
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.
Sep 20 2016
parent reply Karabuta <karabutaworld gmail.com> writes:
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.
Sep 20 2016
parent reply Darren <darren.fielding hotmail.co.uk> writes:
On Tuesday, 20 September 2016 at 19:45:57 UTC, Karabuta wrote:
 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.
Thank you! This does seem to work for packages listed on the dub page (tested it with gl3n). Would you be able to tell me how to install libraries that aren't written in D? A lot of what I need to use are written in C/C++, and I've use dub for bindings to those binaries. But what if I need to compile/build those libraries from scratch, or use/link a static library? I'm not sure if there's a simple answer to this question but I could do with guidance with how to use those libraries with D (other tutorials just focus on C++ with Visual Studio, etc).
Sep 21 2016
parent reply Darren <darren.fielding hotmail.co.uk> writes:
Also I've been making a bit of a mess in dub apparently.  I'm 
getting:

Locally registered package gl3n ~master was not found. Please run 
"dub remove-local C:\Users\Darren\D stuff\opengl\lib".

whenever dub gets used.  Then if I run what it says I get: 
"Missing path to package."

Is there a way to return this to a default setting?
Sep 21 2016
parent Karabuta <karabutaworld gmail.com> writes:
On Wednesday, 21 September 2016 at 16:23:35 UTC, Darren wrote:
 Also I've been making a bit of a mess in dub apparently.  I'm 
 getting:

 Locally registered package gl3n ~master was not found. Please 
 run "dub remove-local C:\Users\Darren\D stuff\opengl\lib".

 whenever dub gets used.  Then if I run what it says I get: 
 "Missing path to package."

 Is there a way to return this to a default setting?
If you have not changed anything in the dub.json file, then run "dub build" to rebuild the packages OR try clearing the dub cache and rebuild. I'm not really familiar with C++ - D bindings (I never wrote C++ code beyond printing a helloworld to the screen). The How To tutorials at https://wiki.dlang.org/Tutorials may help you with bindings and linking process.
Sep 21 2016