On 11/19/2014 6:12 PM, Paul wrote:
I would like to create a simple program using SDL. I've read this page
http://dblog.aldacron.net/derelict-help/using-derelict/ and this one
http://code.dlang.org/about and decided that using 'dub' would be the
sensible option for a beginner so I downloaded the dub executable and
put it in the same directory as my source file 'test.d'.

It doesn't need to be in the same directory as the source. Put it somewhere on the global path.


As per the example at the above url, I created a dub.json file in the
same directory with contents as so:

"dependencies": {
"derelict-sdl2":"~>1.0.0",
"derelict-gl3":"~master",
}

You shouldn't be depending on ~master for anything anymore. The newest version of dub will complain about dependencies on git branches. For derelict-gl3, you can use >=1.0.0.


If I have the relevant import statements in test.d, am I right in
thinking I can use dub to build my program (not just download and build
the derelict libraries)?

Yes, assuming that your dub.json is properly configured.

The command dub build test.d gives me a 'failed
to load package' error.

That's the right command, but the wrong parameters. If you are going to pass a parameter to the build command, it should be the name of a dub package, not the name of a file. Typically, you don't need to pass it a package name if all is properly configured.

Try this:

1 -- make sure dub is on the global path.

2 --
mkdir dubtest
cd dubtest
dub init

You should see the following output in side the dubtest dir

-dub.json
---source
-----app.d

3 --
Edit dub.json and add the following dependencies:

"derelict-sdl2":"~>1.0.0",
"derelict-gl3":">=1.0.0"

4 --
Edit app.d to look like this:

import derelict.opengl3.gl3,
       derelict.sdl2.sdl;

void main()
{
    DerelictGL3.load();
    DerelictSDL2.load();

    import std.stdio : writeln;
    writeln( "Success!");
}

5--
Execute the following command:
dub

You'll see some messages about fetching and building the Derelict packages and then, assuming you have SDL2 and OpenGL on your system library search path, you should see it print "Success!". Otherwise, you'll get a DerelictException of one kind or another.

Note that I didn't give dub a command option. Executing 'dub' with no options will cause it to build and run whatever package is in the current directory. By default, dub will look for source/app.d if you don't configure something differently in dub.json.

Executing 'dub build' will build the executable, but will not run it.


Reply via email to