Froff
Froff

Reputation: 43

How do I build a DAllegro project using dub?

I'm fairly new to D, and wish to use allegro for graphics. I also want to use dub to build my project. However, after running dub add allegro (https://code.dlang.org/packages/allegro), and trying to compile the source code below (using dub), I get an Error: linker exited with status 1. The reason? undefined reference to `al_run_main and undefined reference to `al_install_system.

The sample code is

import allegro5.allegro;

void main()
{
    al_run_allegro(
    {
        al_init();
        //your code goes here
        return 0;
    });
}

I have tried running build_lib_dmd.sh from both my project folder (after copying in the allegro5 folder) and in the folder where dub installed dallegro, but it makes no difference. The example included in the package can successfully be built using build_example_dmd.sh and run using ./example. If i copy the allegro5-directory to my project, I can compile my program using dmd source/app.d allegro5/*.d allegro/internal/*.d (which is what build_lib_dmd does) but I would like to use dub (and I would like to not have the allegro library in my project).

I tried dub add-path allegro5 but that did nothing. What am I missing?

Upvotes: 1

Views: 83

Answers (2)

Froff
Froff

Reputation: 43

While reading the dub cli documentation (https://dub.pm/commandline.html) I found the --rdmd option, which makes dub use rdmd instead of dmd internally. Running dub --rdmd instead of dub fixed the issue.

I think this is because dub internally runs something like dmd -I/path/to/.dub/package source/app.d, which only links the functions I use, and not the ones the package uses. rdmd fixes this.

Upvotes: 1

Michael Parker
Michael Parker

Reputation: 121

Looks like you didn't link with Allegro. The DAllegro5 package is just a binding that allows you to use Allegro in D. You still need to link with the Allegro library. You can use the lib directive in your dub.json (or dub.sdl) to link to any library. Just make sure the library is on your system lib path.

Upvotes: 3

Related Questions