1

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.

beatgammit
  • 19,817
  • 19
  • 86
  • 129
dotnetN00b
  • 5,021
  • 13
  • 62
  • 95
  • Silly question, but have you copied all the files directly or have you kept the structure of the git directory ? If base.d is in the root of your project, allegro5/base.d effectively does not exist. – val May 24 '13 at 17:52
  • Not a silly question at all. I have no idea what I'm doing unfortunately. I've copied the allegro5 folder to the project folder. Now I get different errors. – dotnetN00b May 24 '13 at 19:31
  • @ValentinCLEMENT Now I get Error: unrecognized file extension a – dotnetN00b May 24 '13 at 20:45
  • It is obvious what is the problem - your base module is not in the expected directory named "allegro5". Remember - packages have one-to-one relation with directories. So, if you see a line like `import allegro5.base;` then means you must have a directory named `allegro5` somewhere in your source paths... – DejanLekic May 25 '13 at 10:45
  • Hmm, I think .a files are compiled modules/packages. As DejanLekic pointed out, you have a 1:1 correspondance between modules and files, and packages/directories, which makes it important to have the files in the right place. Can you show us the layout of your project ? – val May 25 '13 at 13:54
  • @ValentinCLEMENT - My path is: C:\Users\Me\Documents\CodeBlock D Projects\D_Allegro_Test\allegro5. Where D_Allegro_Test is the actual project folder. – dotnetN00b May 25 '13 at 18:08

1 Answers1

1

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.

Gassa
  • 8,546
  • 3
  • 29
  • 49