www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - questions about dub

reply thorstein <thorstein novalid.de> writes:
Hi,

I have questions regarding the usage of 'dub'. I'm learning D 
under Win7. I have installed VisualD for the community edition of 
Visual Studio and got some file i/o working.

Next I would like to continue with the mir-tools for matrix 
manipulation. I understood that I have to build them first using 
dub. But I didn't succeed:

C:\..\AppData\Roaming\dub>dub fetch mir-algorithm
Fetching mir-algorithm 0.1.1...
Please note that you need to use `dub run <pkgname>` or add it to 
dependencies of your package to actually use/run it. dub does not 
do actual installation of packages outside of its own ecosystem.

C:\..\AppData\Roaming\dub>dub run mir-algorithm
Building package mir-algorithm in 
C:\..\AppData\Roaming\dub\packages\mir-algorithm-0.1.1\mir-algorithm\
Fetching mir-internal 0.0.5 (getting selected version)...
Main package must have a binary target type, not sourceLibrary. 
Cannot build.

Thats where I stuck.

Beside my specific problem of how to start with the mir-tools I 
wonder how and for what purpose 'dub' is applied when building 
projects in connection with Visual Studio? Or is it just a more 
light-weight command line build tool?

Thanks for shedding some light!
Thorstein
Mar 21 2017
next sibling parent bauss <jj_1337 live.dk> writes:
On Tuesday, 21 March 2017 at 21:01:31 UTC, thorstein wrote:
 Hi,

 I have questions regarding the usage of 'dub'. I'm learning D 
 under Win7. I have installed VisualD for the community edition 
 of Visual Studio and got some file i/o working.

 Next I would like to continue with the mir-tools for matrix 
 manipulation. I understood that I have to build them first 
 using dub. But I didn't succeed:

 C:\..\AppData\Roaming\dub>dub fetch mir-algorithm
 Fetching mir-algorithm 0.1.1...
 Please note that you need to use `dub run <pkgname>` or add it 
 to dependencies of your package to actually use/run it. dub 
 does not do actual installation of packages outside of its own 
 ecosystem.

 C:\..\AppData\Roaming\dub>dub run mir-algorithm
 Building package mir-algorithm in 
 C:\..\AppData\Roaming\dub\packages\mir-algorithm-0.1.1\mir-algorithm\
 Fetching mir-internal 0.0.5 (getting selected version)...
 Main package must have a binary target type, not sourceLibrary. 
 Cannot build.

 Thats where I stuck.

 Beside my specific problem of how to start with the mir-tools I 
 wonder how and for what purpose 'dub' is applied when building 
 projects in connection with Visual Studio? Or is it just a more 
 light-weight command line build tool?

 Thanks for shedding some light!
 Thorstein
Generally if your dub.json or dub.sdl is configured correctly then all you need is to run "dub build" which will invoke package fetching etc. and then your desired compiler. Dependencies are defined in dub.json / dub.sdl using "dependencies" which takes values as "packagename" and then "version". Example: "vibe-d" "~>0.7.28" I don't know if that helps. I'm not familiar with Visual-D and don't use it at all, so I don't know if dub has to be used in specific ways. I compile though command line only, so.
Mar 21 2017
prev sibling next sibling parent kinke <noone nowhere.com> writes:
On Tuesday, 21 March 2017 at 21:01:31 UTC, thorstein wrote:
 C:\..\AppData\Roaming\dub>dub run mir-algorithm
 Building package mir-algorithm in 
 C:\..\AppData\Roaming\dub\packages\mir-algorithm-0.1.1\mir-algorithm\
 Fetching mir-internal 0.0.5 (getting selected version)...
 Main package must have a binary target type, not sourceLibrary. 
 Cannot build.

 Thats where I stuck.
mir is a library, not a program, and dub handles this dependency (and its dependencies) for you if you are going to use it in your program. Check out the official mir docs about how to get up & running with dub: https://github.com/libmir/mir#fast-setup-with-the-dub-package-manager
Mar 21 2017
prev sibling parent reply togrue <tobygruen gmail.com> writes:
On Tuesday, 21 March 2017 at 21:01:31 UTC, thorstein wrote:
 Beside my specific problem of how to start with the mir-tools I 
 wonder how and for what purpose 'dub' is applied when building 
 projects in connection with Visual Studio? Or is it just a more 
 light-weight command line build tool?

 Thanks for shedding some light!
 Thorstein
Hello Thorstein, actually mir-algorithm is a library, and can't be run. A good entry point for dub is https://code.dlang.org/getting_started The overall workflow of dub is something like: 1. Create your own project in a empty folder ( dub init ... ) (this will generate several files) 2. Add your dependencies to "dub.json" (https://code.dlang.org/package-format?lang=json) or "dub.sdl" (https://code.dlang.org/package-format?lang=sdl) Yes, there exist two equivalent file formats that dub can understand. But you don't have to remember the whole syntax to add a few dependencies. The package homepages contain simple snippets you can simply copy/paste into your dub.json or dub.sdl file https://code.dlang.org/packages/mir-algorithm 3. Write code... :) To build and run your application, execute "dub" in the folder where the dub.json / dub.sdl file is located Dub manages downloading the dependencies and building the right version of them.. Very handy! If you want to develop with visual-d you can generate a visual-d project file out of your dub project... ( dub generate visuald ) ~togrue
Mar 21 2017
parent reply thorstein <thorstein novalid.de> writes:
Thanks to all, I got it!

I created a new dub package and copied my code there. Compiles. 
So I guess I get the rest working as well.

Still will have to figure out later the procedure to do the same 
for a VisualD project, if it is possible.

Thorstein
Mar 21 2017
parent reply Mike Parker <aldacron gmail.com> writes:
On Tuesday, 21 March 2017 at 22:51:41 UTC, thorstein wrote:
 Thanks to all, I got it!

 I created a new dub package and copied my code there. Compiles. 
 So I guess I get the rest working as well.

 Still will have to figure out later the procedure to do the 
 same for a VisualD project, if it is possible.

 Thorstein
As togrue said, you can generate a VisualD project from the dub project you created. Normally, you could also just run 'dub build' on any library that has a dub package and copy the resulting binary to a place where you can configure VisualD to find it (and do that for debug/release builds and, if you need both, 32-/64-bit). Unfortunately, mir-algorithm has a target type of "sourceLibrary". It needs to be "library", "staticLibrary", or "dynamicLibrary", in order to build by itself. Using "sourceLibrary" means it can only be built as a dependency to another project. BTW, here's a tip: dub fetch --cache=local mir-algorithm Using --cache=local will put the package in the current directory instead of the AppData path. When you aren't using dub to manage your own projects, that makes it easier to deal with (e.g. cd C:\dev\dub\package-name). You can cd to the package's root directory and run dub build, then add the path to the resultant library to your IDE, or copy the library to a common path.
Mar 21 2017
parent reply Mike Parker <aldacron gmail.com> writes:
On Wednesday, 22 March 2017 at 04:06:50 UTC, Mike Parker wrote:

 dub fetch --cache=local mir-algorithm

 Using --cache=local will put the package in the current 
 directory instead of the AppData path. When you aren't using 
 dub to manage your own projects, that makes it easier to deal 
 with (e.g. cd C:\dev\dub\package-name). You can cd to the 
 package's root directory and run dub build, then add the path 
 to the resultant library to your IDE, or copy the library to a 
 common path.
Sorry, forgot to mention. With this approach, you also have to build any dependencies and link them in. And you'll want to specify where to find the dependencies if they aren't in the global cache. I have examples of doing this in the Derelict documentation: http://derelictorg.github.io/building/without-dub/
Mar 21 2017
parent thorstein <thorstein novalid.de> writes:
Ups, somehow overread the last sentence of tourge :)

Thanks for the detailed insights!
Mar 21 2017