dotnetN00b
dotnetN00b

Reputation: 5131

Why isn't CodeBlocks letting me compile this example Allegro program?

Basically I'm having a problem with getting an Allegro binding (D + Allegro) to work with Code:Blocks. I think it's a settings problem, but I'm not sure where. So here's what I've done so far...

Error: module base is in file 'allegro5\base.d' which cannot be read|

This is the error I keep getting. I'm using Windows 7, DAllegro5, Code:Blocks, and the D language DMD compiler.

Code:Blocks works. Compiling a regular D project works. I've added the DAllegro5 files to the project, but I keep getting this error. What else should I do to get this error to go away?

I followed the instructions here.

You have two options here. You can copy all the modules into your project, and just use them like that. Alternatively, you can compile the binding into a static library for convenience:

I did the bolded. Just copied the actual .d files to my project.

Upvotes: 1

Views: 845

Answers (1)

Gassa
Gassa

Reputation: 8846

The "you can copy all the modules into your project" path is in fact not much easier than the alternative one, which is to build the library separately.

Anyway, here's a step-by-step that worked for me. Note that this applies to Windows + Code::Blocks + Allegro5 + DMD chain, assuming that compiling a D project in Code::Blocks already works. Specifically, this does not apply to other D compilers, GDC and LDC.

Part I

  1. Create a Code::Blocks D project, remove all example D sources if they are present.

  2. Download and copy the whole https://github.com/SiegeLord/DAllegro5 to the directory of that project, preserving the directory structure.

  3. Add all the .d files recursively by navigating to Project - Add files recursively... in Code::Blocks (example.d and allegro5/*, right now it was 49 files in total).

If you build the project now, it will complain, like:

||=== Build: Debug in [your-project-name] (compiler: Digital Mars D Compiler) ===| || Symbol Undefined _al_run_main| || Symbol Undefined _al_install_mouse| || Symbol Undefined _al_draw_triangle| ... ||=== Build failed: 26 error(s), 0 warning(s) (0 minute(s), 6 second(s)) ===|

That is, the linker can't find any of the library functions. And here's the catch: you should now obtain an Allegro5 binary in COFF .lib format. And as far as I can tell, it is not exactly lying around for us in a trusted place: the .lib binaries supplied by Allegro developers are in OMF format. To get it, you will need an Allegro DLL, perhaps from Allegro's main site, and a program to perform the DLL-to-COFF conversion, perhaps from D compiler's site. The process is detailed below.

Part II

  1. To get an Allegro5 DLL, go to https://www.allegro.cc/files/ and download some binary.

  2. To get the converter, obtain an implib.exe from DigitalMars. For example, go to http://www.digitalmars.com/download/freecompiler.html and download the basic utilities from there (the link is http://ftp.digitalmars.com/bup.zip).

  3. The easiest route now is to grab a single Allegro5 DLL containing all the library functions (as opposed to using modules like allegro-*.dll, allegro_font-*.dll, allegro_primitives-*.dll separately). Running a command such as implib /s dallegro5.lib allegro-5.0.10-monolith-mt.dll will produce a .lib file in COFF format from the existing DLL file. Here, the "/s" option is needed to prepend an underscore to function names, so that, for example, "al_run_main" is called "_al_run_main" in the .lib file. The naming of Allegro5 DLL files (what is monolith, md or mt, etc.) is explained here: https://www.allegro.cc/manual/5/install/windows.html.

Now is the time we get back to our Code::Blocks project.

Part III

  1. Copy both the DLL (allegro-5.0.10-monolith-mt.dll) and the lib (dallegro5.lib) into the root of our Code::Blocks project directory. A bit of a mess there, but you can move things to a more appropriate location later, when you already have a working configuration.

  2. In Code::Blocks, navigate to Project - Build options... - Linker settings and add your newly created "dallegro5.lib" to the list of libraries.

  3. Rebuild the project and run it. Everything should be working now.

Please tell if all of the above worked for you — and if not, what is the failing step, and what exactly went wrong.

Upvotes: 1

Related Questions