I am looking for correct detailed instructions how to build Allegro....
takis76

Hello,
I am trying to build the Allegro library from the source code but even I did a research in the forums (not here, here the forums look empty), but in stack overflow or in other search results finding these webpages:

http://members.allegro.cc/EdgarReynaldo/BuildA4.html
http://members.allegro.cc/EdgarReynaldo/BuildA5.html
https://wiki.opensurge2d.org/Compiling_the_Source_Code

And other scattered results from threads and posts.
When I was tried to compile one dependency the next produce more errors.
Almost all the information and guides that suppose to help you to build the Allegro 4.4.2 and Allegro 5.x end to drop you compile errors leaving you unable to fix them, unable to compile the next dependency and these errors are unknown to me.

I installed and the msys it needs, and the mingwg64 it needs, and I run and this cmake thing it needs (I tried to configure it and press this generate button), by guessing what it misses, the one compile misses another and then you are ending in a fatal not continuing error because the needed dependency is unable to be compiled.

You will say to post a screenshot to see the error. It is better if there is or if someone like or did post a complete detailed building guide, not the draft guides that exist, a guide that will tell you what to download exactly, where to download, what version download exactly, which dependency download exactly and where to put it exactly and show the cmake options (This red list) what to choose, what missing folders needed and in which order each dependency need to be compiled. (The web pages I saw here suppose they present the order which dependencies need to be installed first but again more unknow errors appear and the needed dependency is not compiling and I do not know how to even describe the error to the search engine for a solution), there is no solution and the similar solutions are not working with allegro.

Last time I used Allegro was the Allegro 4.2 (The old one you say and it is not supported and not used anymore and not recommended). But Allegro 4.4 and Allegro 5 is a total mess and it does not compile. (Why do people do things complex?). I remember 10 years ago you run a command fix djgpp (I have used since the DOS and djgpp compiler) and then you typed make and make install and the whole Allegro was ready. Now it is total mess.

I haven't used is since the version increased to 4.4 (I tried to compile and more recent versions without luck) and I never was able to compile it.
You will say now why do I will not use the precompiled versions?

The precompiled version have the libraries only not the extras. I do not know if the precompiled versions has the addons (zlib,libpng,freetype etc) inside precompiled?

Also when you compiled the Allegro 4.2 there was one nice program with name Grabber (It created data files and you stored your assets in( and I see there is not any Grabber precompiled. (Does the grabber exist in Allegro 5)?

Thank you and I would like someone to post some very full detailed guide about how to build the Allegro for its source code. How did you build your own versions you have in your computers? (Also I am interested in windows version building).

Thank you.

SiegeLord

There's at least two options here.

First, you can use the repository from which the precompiled binaries are made, https://github.com/liballeg/allegro_winpkg/tree/master/universal. See README_msys.txt for instructions and what to download (no much, since this repository vendors the dependencies). The precompiled binaries come with a good amount of dependencies statically linked into the Allegro DLLs.

If you want a more manual approach more suitable for hacking on Allegro, you can follow https://www.allegro.cc/forums/thread/616828, which we'll eventually add to the wiki.

takis76 said:

Also when you compiled the Allegro 4.2 there was one nice program with name Grabber (It created data files and you stored your assets in( and I see there is not any Grabber precompiled. (Does the grabber exist in Allegro 5)?

You can use the PhysFS addon to load files from .zip files. See ex_physfs for an example.

Edgar Reynaldo

I am Edgar Reynaldo, and I put together those guides. They assume you have at least some familiarity with building a software library. If they are not detailed enough you need to tell me what they are missing.

It also assumes you have some experience with CMake and / or Autotools like configure.

First of all, why do you want to build allegro from source? If you just want to make programs that use allegro then use the binaries. You only need to build allegro from source if you are modifying the libraries source code.

The thread SiegeLord quoted tells you how to build with MSYS2. It is easier than building with MinGW-W64 manually.

I offer downloads of pre-compiled MinGW-W64 binaries at the bottom of the guide. They include all the pre-compiled dependencies that I was able to compile. You can use the deps to build allegro if you like.

Also, there is no "definitive" guide to building allegro 5 with MinGW-W64. It entirely depends on which versions of the dependency libraries you use, how skilled you are with CMake and configure, and how intuitive you are at solving errors.

We can help you with errors, but text is more useful than screenshots generally. Like I said, if you think my guides are missing details then tell me what you would like and I will consider adding it.

takis76

Hello,
Thank you very much you answered my question.

I liked to build the Allegro library from the source to generate the Grabber tool. But as you say there is not Grabber tool anymore.

I didn't know what is PhysFS was. Its name seems to be like a Physics library.
What is this PhysFS? A new kind of Grabber that supports zip files?

Usually zip libraries extracts all the assets from the zip file they do not read them directly from zip file. If the PhysFS, loads an asset from the zip without extract it on run time and can be able to create and new zip files on run time it will be great.

I will retry to compile the Allegro 5, (I would like to try to compile it again just for a knowledge).
I do not know anything about CMake and Autotools, that's why I wasn't able to continue the compilation when an error appeared.

That's why I was asked to tell me which version of MinGW is needed, which version of CMake is needed, (There are many different versions that are not compatible for each version of Allegro). I will compile it again and I will post my error messages and I will tell you what I did exactly.

Also I like to compile the Allegro library from the source because I want a monolith version and not need to ship dlls with my games and programs.

And I will visit the links you gave me too.

Thank you very much. Have and happy Christmas too.

Edgar Reynaldo

The grabber tool only works with Allegro 4, and gets built by default when building allegro 4. The Allegro 5 alternative is as SiegeLord said, the PhysFS addon (FileSystem) which allows you to load files contained within archives such as .zip files, .7z files, and so on...

The PhysFS addon allows you to load files contained within archives as if they were already extracted from the zip file. So, for example you can use Allegro 5 and PhysFS to load an image file directly from an archive.

As for which version of MinGW to use I recommend MinGW-W64 with GCC version 7 at least. CMake probably requires version 3.0 or better to compile Allegro but I'm not sure of a specific version necessary.

I suggest either you use MSYS2 as SiegeLord suggested because it is easier to install the dependencies since all you have to understand is how to use a package manager. Otherwise you can build Allegro 5 using the deps that come in my binaries. Those binaries also include PhysFS and the PhysFS addon.

Depends on what you want to do.

EDIT for your edit
If you don't want DLLs to ship alongside your program, you need the static version of Allegro and the static dependencies.

The monolith just puts everything into a single dll or archive, depending on whether you build it dynamically or statically.

SiegeLord

The PhysFS addon allows you to load files contained within archives as if they were already extracted from the zip file. So, for example you can use Allegro 5 and PhysFS to load an image file directly from an archive.

To add to this... the equivalent of the grabber for A5 is your favorite zip program, be it the built in Windows one, or 7-zip or w/e. The PhysFS addon is the replacement for things like load_datafile etc, although it works completely differently. Roughly speaking, with PhysFS you 'mount' zip files as virtual directories, and then load your asserts via regular al_load_* calls.

takis76

Ok, I begun to follow the instructions you gave me from here: https://www.allegro.cc/forums/thread/616828

First I installed the MSYS2, I completely removed my MSys1.10 I had installed and I deleted and the remained folder.
So a new folder with name msys was created to my c:
I run the msys2 immediately after the installation which I think the MSYS2 MSYS was run.

I followed everything in section "I".
The I installed the c++ compiler. I followed everything in section "II"

In the section "III" I skipped the section "A" installing the Allegro from msys because it says the Allegro will lag. (I do not understand what means. Lag it will be slow?) I skipped this.
And I jumped to Section "III" - "B".
In section "III" - "B" I skipped the part "1" because I didn't install the lag version of Allegro.

I executed the commands:
pacman -S make
pacman -S mingw-w64-x86_64-cmake
pacman -S git

And in the fourth command:
pacman -S mingw-w64-x86_64-pkg-config

I have an error. And now the organs begin. :P

resolving dependencies...
looking for conflicting packages...
:: mingw-w64-x86_64-pkg-config and mingw-w64-x86_64-pkgconf are in conflict. Remove mingw-w64-x86_64-pkgconf? [Y/n] y
error: failed to prepare transaction (could not satisfy dependencies)
:: removing mingw-w64-x86_64-pkgconf breaks dependency 'mingw-w64-x86_64-pkgconf' required by mingw-w64-x86_64-cmake

As I understand the dependencies wasn't installed, because I skipped the whole section "III" - "A" because the Allegro will lag. So as I understood now, I will not execute this command yet:
pacman -S mingw-w64-x86_64-allegro

but I will execute the rest to have the dependencies downloaded at least.

These:
mingw-w64-x86_64-dumb: allegro_audio
mingw-w64-x86_64-flac: allegro_audio
mingw-w64-x86_64-opusfile: allegro_audio
mingw-w64-x86_64-freetype: allegro_font
mingw-w64-x86_64-libjpeg-turbo: allegro_image
mingw-w64-x86_64-libpng: allegro_image
mingw-w64-x86_64-libvorbis: allegro_audio
mingw-w64-x86_64-openal: allegro_audio
mingw-w64-x86_64-physfs: allegro_physfs

I will try and I will tell you.

Well, I installed the dependencies and I receive the same error.
when I retried to run the command:
pacman -S mingw-w64-x86_64-pkg-config

After installed (I think) the dependencies (It asked to install and I press y).

  1. pacman -S mingw-w64-x86_64-pkg-config

resolving dependencies...
looking for conflicting packages...
:: mingw-w64-x86_64-pkg-config and mingw-w64-x86_64-pkgconf are in conflict. Remove mingw-w64-x86_64-pkgconf? [Y/n] y
error: failed to prepare transaction (could not satisfy dependencies)
:: removing mingw-w64-x86_64-pkgconf breaks dependency 'mingw-w64-x86_64-pkgconf' required by mingw-w64-x86_64-cmake

Now I stuck.

SiegeLord

Thanks for trying it. You can skip the mingw-w64-x86_64-pkg-config package, its not necessary.

I think the build section of that guide is a bit problematic too, I'd recommend just doing this:

git clone https://github.com/liballeg/allegro5.git
cd allegro5
mkdir build
cd build
cmake .. -G"MSYS Makefiles"
make
make install

takis76

Do all the process I did above except the: pacman -S mingw-w64-x86_64-pkg-config
was correct?
Do I call git from inside the msys environment?

Where the final allegro will be installed. I see everything are getting installed inside my c:\msys directory.

During the making of Allegro many warnings like this were appeared:

C:/msys/home/Takis76/allegro5/demos/skater/src/framework.c: In function 'init_framework':
C:/msys/home/Takis76/allegro5/demos/skater/src/framework.c:89:4: warning: 'strncpy' specified bound 1024 equals destination size [-Wstringop-truncation]
   89 |    strncpy(config_path, al_path_cstr(path, '/'), DEMO_PATH_LENGTH);
      |    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
C:/msys/home/Takis76/allegro5/demos/skater/src/framework.c:102:4: warning: 'strncpy' specified bound 1024 equals destination size [-Wstringop-truncation]
  102 |    strncpy(data_path, al_path_cstr(path, '/'), DEMO_PATH_LENGTH);
      |    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


C:/msys/home/Takis76/allegro5/demos/shooter/title.c: In function 'load_credits':
C:/msys/home/Takis76/allegro5/demos/shooter/title.c:59:4: warning: ISO C90 forbids mixed declarations and code [-Wdeclaration-after-statement]

After millions of warnings it compiled inside my msys folder.
Will I copy the build folder outside of my msys and rename it to allegro?

It is in folder like this:
C:\msys\home\Takis76\allegro5\build

Why is it inside too many sub folders?

I would like to test if is it working.
I will try to use code::blocks as an IDE.

But I have and other questions, where is the manual? where are the sources of the examples? How do I build the static libraries and the debug?

When you try to run the examples it asks for missing dlls that are not exist.
For example if you run the example ex_mouse.exe if asks for missing dlls.

libjpeg-8.dll
libpng16-16.dll
libgcc_s_seh-1.dll
libstdc++-6.dll

The only related image dll is the "allegro_image-5.2.dll" that was generated after compile but even if you copy it and rename it to libjpeg-8.dll and libpng16-16.dll you try to trick the program there are no libgcc_s_seh-1.dll and libstdc++-6.dll

And the trick is not working. (Look at the "Trick_Error.jpg" I uploaded here). So there are many missing dlls, but I prefer a static build not depend on dlls.

Thank you.

Edgar Reynaldo

There's a cmake-gui option called PREFER_STATIC_DEPS. Turn that on and reconfigure and see if if changes the libraries to static ones. Otherwise you'll have to specify the static libraries yourself. Because otherwise the dynamic libraries will be used to link to, and then it depends on the dlls.

Edit to remove the few remaining dependencies, you need to link with the static ones.

gcc -o a.exe main.c -static -lpthread -static-libstdc++ -static-libgcc

takis76

Hello,
Thank you for the answer.

If I will try to run cmake-gui .. inside the build subdirectory in allegro5
I have this error.

C:/msys/mingw64/bin/cmake-gui.exe: error while loading shared libraries: zlib1.dll: cannot open shared object file: No such file or directory

I run this command to load the cmake-gui to add this PREFER_STATIC_DEPS option you said.
But there are more errors. The cmak-gui is not opening

I think I installed the zlib dependency why did not find it?

If I will try to load the cmake-gui not from the Msys but from normal command prompt

cd C:\msys\home\Takis76\allegro5\build
and run the cmake-gui from there

it shows other error about missing libraries Qt6Widgets.dll , Qt6Gui.dll and Qt6Core.dll

I am about to quit trying build this library and using the Allegro in general.

Have a very happy new year.

Edgar Reynaldo

Please don't give up. It's not as hard as it seems, and it's also harder than it looks, but it's worth it.

I can provide you with an easier way to get started. Just use the dependency binaries I used to build allegro.

http://winlibs.com

Here, I made a release of Eagle, with Allegro 5.2.7.1 and dependencies provided.

https://github.com/EdgarReynaldo/EagleGUI/releases/tag/0pt8pt4

Download the allegro binaries (that come with the dependencies) and then use them to build allegro to your liking. I know they all work with this version of Allegro.

takis76

Hello again,
Happy new year :)
I will retry to compile it. But I do not understand much. The winlibs.com contains instructions and files about Gcc and MinGW-w64 versions.

Here after the failed compiles of Allegro I have Gcc version 4.5.0

Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=c:/mingw/bin/../libexec/gcc/i686-pc-mingw32/4.5.0/lto-wrapper.exe
Target: i686-pc-mingw32
Configured with: ../src/configure --prefix=/c/temp/gcc/dest --enable-languages=c,c++ --with-arch=i686 --with-tune=generic --disable-libstdcxx-pch --disable-nls --disable-shared --disable-sjlj-exceptions --disable-win32-registry --enable-checking=release
Thread model: win32
gcc version 4.5.0 (GCC)

But I use to use the version 8.1.0 for my BlitzMax projects.

Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=C:/MinGW/bin/../libexec/gcc/i686-w64-mingw32/8.1.0/lto-wrapper.exe
Target: i686-w64-mingw32
Configured with: ../../../src/gcc-8.1.0/configure --host=i686-w64-mingw32 --build=i686-w64-mingw32 --target=i686-w64-mingw32 --prefix=/mingw32 --with-sysroot=/c/mingw810/i686-810-win32-sjlj-rt_v6-rev0/mingw32 --enable-shared --enable-static --enable-targets=all --enable-multilib --enable-languages=c,c++,fortran,lto --enable-libstdcxx-time=yes --enable-threads=win32 --enable-libgomp --enable-libatomic --enable-lto --enable-graphite --enable-checking=release --enable-fully-dynamic-string --enable-version-specific-runtime-libs --enable-sjlj-exceptions --disable-libstdcxx-pch --disable-libstdcxx-debug --enable-bootstrap --disable-rpath --disable-win32-registry --disable-nls --disable-werror --disable-symvers --with-gnu-as --with-gnu-ld --with-arch-32=i686 --with-arch-64=nocona --with-tune-32=generic --with-tune-64=core2 --with-libiconv --with-system-zlib --with-gmp=/c/mingw810/prerequisites/i686-w64-mingw32-static --with-mpfr=/c/mingw810/prerequisites/i686-w64-mingw32-static --with-mpc=/c/mingw810/prerequisites/i686-w64-mingw32-static --with-isl=/c/mingw810/prerequisites/i686-w64-mingw32-static --with-pkgversion='i686-win32-sjlj-rev0, Built by MinGW-W64 project' --with-bugurl=https://sourceforge.net/projects/mingw-w64 CFLAGS='-O2 -pipe -fno-ident -I/c/mingw810/i686-810-win32-sjlj-rt_v6-rev0/mingw32/opt/include -I/c/mingw810/prerequisites/i686-zlib-static/include -I/c/mingw810/prerequisites/i686-w64-mingw32-static/include' CXXFLAGS='-O2 -pipe -fno-ident -I/c/mingw810/i686-810-win32-sjlj-rt_v6-rev0/mingw32/opt/include -I/c/mingw810/prerequisites/i686-zlib-static/include -I/c/mingw810/prerequisites/i686-w64-mingw32-static/include' CPPFLAGS=' -I/c/mingw810/i686-810-win32-sjlj-rt_v6-rev0/mingw32/opt/include -I/c/mingw810/prerequisites/i686-zlib-static/include -I/c/mingw810/prerequisites/i686-w64-mingw32-static/include' LDFLAGS='-pipe -fno-ident -L/c/mingw810/i686-810-win32-sjlj-rt_v6-rev0/mingw32/opt/lib -L/c/mingw810/prerequisites/i686-zlib-static/lib -L/c/mingw810/prerequisites/i686-w64-mingw32-static/lib -Wl,--large-address-aware'
Thread model: win32
gcc version 8.1.0 (i686-win32-sjlj-rev0, Built by MinGW-W64 project)

If I will use my Mingw version 8.1.0 will the Allegro be compiled?

Is this Eagle is a GUI library? (Interesting) I am looking for a nice GUI library that
contains full skinable gadgets (Pulldown menus, list gadget, option button, check gadget, ratio button gadget, horizontal and vertical scrollbars, buttons, image buttons, input box, labels, tabs, panels, windows gadgets, multi line input box, spinner, canvas gadget and other nice gadgets). Do these supported with Eagle GUI?

I will try it if I will ever be able to compile Allegro. Also I liked the built in Allegro GUI too.

I will try to download the Allegro Binaries and I will skip compile it and I will try to see if I will manage to use Code:Blocks. (There is not grabber any more and I will try to use the PhysFS library).

I tried to find the missing Qt6 dlls to run my cmake-gui but it asks for Qt6 version of dlls and I can't find them, only in Qt5 exits. I am unlucky.

I will try to download the precompiled Allegro 5.2.7.1 from the link you gave.

Update:

I created a folder with name Allegro5 on my C:\Allegro5

I created a code::blocks new project.
I didn't use the exact instruction for code:block of the instructions you provided because I use minGw 8.5.0 as my compiler. But I used similar with my own MingGw compiler.

In Project Build Options:
In the linker settings tab and Link Library list I put "C:\Allegro5\lib\liballegro_monolith-static.a"

For Debug Target:
In the linker settings tab and Link Library list I put
"C:\Allegro5\lib\liballegro_monolith-debug-static.a"

For Release Target:
In the linker settings tab and Link Library list I put
"C:\Allegro5\lib\liballegro_monolith-static.a"

In Search Directories tab and in the compiler tab I put
"C:\Allegro5\Include\"

In Search Directories tab and in the Linker tab I put
"C:\Allegro5\lib"

Are these correct first?

When I run a small source code I have lots of undefined reference errors:

C:\Allegro5\lib\liballegro_monolith-static.a(wsystem.c.obj):wsystem.c:(.text+0x4c7): undefined reference to `__imp_timeEndPeriod'
C:\Allegro5\lib\liballegro_monolith-static.a(wsystem.c.obj):wsystem.c:(.text+0x11c4): undefined reference to `__imp_PathFindOnPathW'
C:\Allegro5\lib\liballegro_monolith-static.a(wsystem.c.obj):wsystem.c:(.text+0x1643): undefined reference to `__imp_timeBeginPeriod'
C:\Allegro5\lib\liballegro_monolith-static.a(wtime.c.obj):wtime.c:(.text+0x18): undefined reference to `__imp_timeGetTime'
C:\Allegro5\lib\liballegro_monolith-static.a(wtime.c.obj):wtime.c:(.text+0x14a): undefined reference to `__imp_timeGetTime'
C:\Allegro5\lib\liballegro_monolith-static.a(wtime.c.obj):wtime.c:(.text+0x1fd): undefined reference to `__imp_timeGetTime'
C:\Allegro5\lib\liballegro_monolith-static.a(wtime.c.obj):wtime.c:(.text+0x222): undefined reference to `__imp_timeGetTime'
C:\Allegro5\lib\liballegro_monolith-static.a(wxthread.c.obj):wxthread.c:(.text+0x41b): undefined reference to `__imp_timeGetTime'
C:\Allegro5\lib\liballegro_monolith-static.a(ogl_shader.c.obj):ogl_shader.c:(.text+0x2a3): undefined reference to `__imp_glGetError'
C:\Allegro5\lib\liballegro_monolith-static.a(ogl_shader.c.obj):ogl_shader.c:(.text+0x5f6): undefined reference to `__imp_glGetError'
C:\Allegro5\lib\liballegro_monolith-static.a(ogl_shader.c.obj):ogl_shader.c:(.text+0x743): undefined reference to `__imp_glGetError'
C:\Allegro5\lib\liballegro_monolith-static.a(ogl_shader.c.obj):ogl_shader.c:(.text+0x842): undefined reference to `__imp_glGetError'
C:\Allegro5\lib\liballegro_monolith-static.a(ogl_shader.c.obj):ogl_shader.c:(.text+0x948): undefined reference to `__imp_glGetError'
C:\Allegro5\lib\liballegro_monolith-static.a(ogl_shader.c.obj):ogl_shader.c:(.text+0xa5b): more undefined references to `__imp_glGetError' follow
C:\Allegro5\lib\liballegro_monolith-static.a(ogl_shader.c.obj):ogl_shader.c:(.text+0xebd): undefined reference to `__imp_glBindTexture'
C:\Allegro5\lib\liballegro_monolith-static.a(ogl_shader.c.obj):ogl_shader.c:(.text+0xed2): undefined reference to `__imp_glGetError'
C:\Allegro5\lib\liballegro_monolith-static.a(wgl_disp.c.obj):wgl_disp.c:(.text+0x10a): undefined reference to `__imp_glFlush'
C:\Allegro5\lib\liballegro_monolith-static.a(wgl_disp.c.obj):wgl_disp.c:(.text+0x46a): undefined reference to `__imp_wglDeleteContext'
C:\Allegro5\lib\liballegro_monolith-static.a(wgl_disp.c.obj):wgl_disp.c:(.text+0xd8e): undefined reference to `__imp_wglCreateContext'
C:\Allegro5\lib\liballegro_monolith-static.a(wgl_disp.c.obj):wgl_disp.c:(.text+0xda6): undefined reference to `__imp_wglMakeCurrent'
C:\Allegro5\lib\liballegro_monolith-static.a(wgl_disp.c.obj):wgl_disp.c:(.text+0xe8f): undefined reference to `__imp_wglDeleteContext'
C:\Allegro5\lib\liballegro_monolith-static.a(wgl_disp.c.obj):wgl_disp.c:(.text+0x1091): undefined reference to `__imp_glFlush'
C:\Allegro5\lib\liballegro_monolith-static.a(wgl_disp.c.obj):wgl_disp.c:(.text+0x10b2): undefined reference to `__imp_glFlush'
C:\Allegro5\lib\liballegro_monolith-static.a(wgl_disp.c.obj):wgl_disp.c:(.text+0x10da): undefined reference to `__imp_wglMakeCurrent'
C:\Allegro5\lib\liballegro_monolith-static.a(wgl_disp.c.obj):wgl_disp.c:(.text+0x114b): undefined reference to `__imp_wglGetCurrentContext'
C:\Allegro5\lib\liballegro_monolith-static.a(wgl_disp.c.obj):wgl_disp.c:(.text+0x116b): undefined reference to `__imp_wglMakeCurrent'
C:\Allegro5\lib\liballegro_monolith-static.a(wgl_disp.c.obj):wgl_disp.c:(.text+0x1371): undefined reference to `__imp_wglGetCurrentContext'
C:\Allegro5\lib\liballegro_monolith-static.a(wgl_disp.c.obj):wgl_disp.c:(.text+0x137c): undefined reference to `__imp_wglGetCurrentDC'

blah blah...

Update2:

If I will change all static libraries to dlls I do not have undefined reference error
but I need to have lots of dlls in the same directory with the .exe file.

How is it possible not have many dlls shipped with my program? (I thought to use the static libraries that have no dll prefix in their filenames).

For Example:

For this instead: "liballegro_monolith.dll.a"
To use this: "liballegro_monolith.a"
Or is supposed to use this: "liballegro_monolith-static.a"

Using the static or the one without the static predix (But not dll). Generates undefined reference errors

Creating a very small source code to see if the library work using this code:

#SelectExpand
1#include <stdio.h> 2#include <allegro5/allegro.h> 3 4const float FPS = 60; 5ALLEGRO_DISPLAY *display; 6 7 8int main() 9{ 10 11 al_init(); 12 al_create_display(800, 600); 13 14 bool running = true; 15 16 // Game loop 17 while (running) 18 { 19 20 } 21 al_flip_display(); 22 23return 0; 24}

I have this error:

The procedure entry point _ZSt28__throw_bad_array_new_lengthv could not be located in the dynamic link library "OpenAL32.dll".

At least this compiled.

First I will need to have the programs independent without dlls.
Then it seems the OpenAL32.dll is missing something.
Is there an option to use and Directx 9 or 10 or 11 if you want?

And something else the IDE is not recognizing the Allegro's commands when you type them and they didn't change color which means they didn't add in the vocabulary.

It seems I will start from scratch completely.

Edgar Reynaldo

If you link statically, you need to link all the windows libraries too. And it looks like you need OpenGL.


-static 
-ljpeg 
-ldumb
-lwebp
-lFLAC 
-ltheora
-lvorbisfile 
-lvorbis 
-logg 
-lphysfs 
-lfreetype 
-lpng16 
-lzlibstatic 
-lopenal32
-ldsound
-lgdiplus 
-luuid 
-lkernel32 
-lwinmm 
-lpsapi 
-lopengl32 
-lglu32 
-luser32 
-lcomdlg32 
-lgdi32 
-lshell32 
-lole32 
-ladvapi32 
-lws2_32 
-lshlwapi 
-lpthread
-static-libstdc++ 
-static-libgcc

I may have built the static libs wrong if they need OpenAL32.dll or anything else.

takis76

I haven't build any libraries I use your already built of yours because I haven't managed to build Allegro, I am trying to compile a test source code and skipping the Allegro Build process.
And I downloaded your Allegro 5.2.7.1 version from the link you gave me.

Allegro5271GIT_2021-12-12_x86_64-w64-mingw32_gcc11.2_posix_seh.7z

I downloaded this file I extracted it in a new Allegro5 folder and I am trying to
compile a test source code.

I added all the list with link commands in the linker.

And I used the "C:\Allegro5\lib\liballegro_monolith-static.a" as library.
It suppose to have all these sub libraries inside.

But the OpenGL is still missing. Where do I will download this OpenGL missing library?

I receive undefined references.

Screenshot

https://prnt.sc/260btky

Edgar Reynaldo

If you use my binaries, you need to use the same compiler they were compiled with, otherwise it won't work.

liballegro_monolith-debug-static does NOT contain ANY of the dep libraries that's why you need to link with them all.

OpenGL comes with your compiler. -lopengl32 -lglu32

takis76

You mean to use the Mingw 11 and not 8.5.0?
After adding the -lopengl32 -lglu32 I still receive the same opengl undefined reference errors.

C:\Allegro5\lib\liballegro_monolith-static.a(wsystem.c.obj):wsystem.c|| undefined reference to `__imp_timeEndPeriod'|
C:\Allegro5\lib\liballegro_monolith-static.a(wsystem.c.obj):wsystem.c|| undefined reference to `__imp_PathFindOnPathW'|
C:\Allegro5\lib\liballegro_monolith-static.a(wtime.c.obj):wtime.c|| undefined reference to `__imp_timeGetTime'|
C:\Allegro5\lib\liballegro_monolith-static.a(wxthread.c.obj):wxthread.c|| undefined reference to `__imp_timeGetTime'|
C:\Allegro5\lib\liballegro_monolith-static.a(ogl_shader.c.obj):ogl_shader.c|| undefined reference to `__imp_glGetError'|

And lots of others...

GullRaDriel

timegettime is in Winmm.lib or Winmm.dll.

Dizzy Egg

So long as your "other link options" is the same as below, you should be ok (you don't need anything in "Link Libraries"):

-lallegro_monolith-debug-static
-ljpeg
-ldumb
-lFLAC
-lfreetype
-lvorbisfile
-lvorbis
-logg
-lphysfs
-lpng16
-lzlibstatic
-ldsound
-lgdiplus
-luuid
-lkernel32
-lwinmm
-lpsapi
-lopengl32
-lglu32
-luser32
-lcomdlg32
-lgdi32
-lshell32
-lole32
-ladvapi32
-lws2_32
-lshlwapi

takis76

I used the new list of linker commands and I have this error now:

||=== Build: Release in Adventure Maker (compiler: GNU GCC Compiler) ===|
C:\Allegro5\lib\liballegro_monolith-debug-static.a(display.c.obj)||In function `al_create_display':|
E:\usr64\libs\Allegro52X\src\display.c|59|undefined reference to `__imp__wassert'|
C:\Allegro5\lib\liballegro_monolith-debug-static.a(display.c.obj)||In function `al_destroy_display':|
E:\usr64\libs\Allegro52X\src\display.c|166|undefined reference to `__imp__wassert'|
C:\Allegro5\lib\liballegro_monolith-debug-static.a(display.c.obj)||In function `al_get_backbuffer':|
E:\usr64\libs\Allegro52X\src\display.c|178|undefined reference to `__imp__wassert'|
C:\Allegro5\lib\liballegro_monolith-debug-static.a(display.c.obj)||In function `al_flip_display':|
E:\usr64\libs\Allegro52X\src\display.c|193|undefined reference to `__imp__wassert'|
C:\Allegro5\lib\liballegro_monolith-debug-static.a(display.c.obj)||In function `al_update_display_region':|
E:\usr64\libs\Allegro52X\src\display.c|207|undefined reference to `__imp__wassert'|
C:\Allegro5\lib\liballegro_monolith-debug-static.a(display.c.obj):E:\usr64\libs\Allegro52X\src\display.c|218|more undefined references to `__imp__wassert' follow|
||error: ld returned 1 exit status|
||=== Build failed: 7 error(s), 0 warning(s) (0 minute(s), 1 second(s)) ===|

Dizzy Egg said:

So long as your "other link options" is the same as below, you should be ok (you don't need anything in "Link Libraries"):

Do I need to remove the "C:\Allegro5\lib\liballegro_monolith-static.a" from the link library?

Update.

I removed the library from the "Linker Libraries" and I left the other linker options but I have the same error.

Dizzy Egg

I don't know why it's referencing something in E:\ drive?

Have you setup your "Search Directories->Linker options" correctly?

takis76

Search directories for compiler: C:\Allegro5\Include\
Search directories for the linker: C:\Allegro5\lib

About the library tries to search on my E: Drive

I do not have any directory with name usr64 on my E: Drive and I haven't installed my Allegro on my E: Drive too.

Dizzy Egg

I don't know what the issue is here; if I use the version Edgar posted earlier (https://github.com/EdgarReynaldo/EagleGUI/releases/tag/0pt8pt4) I can't even get it to link!

I'm using an older Mingw version of Allegro5 (Allegro522_MinGW5303v2) and it works fine. If I try to use the one Edgar posted it compiles but will not link (undefined references).

I would post my version for you to try but the attachments seem broken on this site.

EDIT: This is the one I use with CodeBlocks/Mingw and it works fine:

https://sourceforge.net/projects/unofficialmingw/files/MinGW5302v3.tar.7z/download

Edgar Reynaldo

You also need to define ALLEGRO_STATICLINK.

-DALLEGRO_STATICLINK or #define ALLEGRO_STATICLINK in every file that includes allegro.

Dizzy Egg

Ahh, didn’t try that! Will give it a go when I’m sober.

Edgar Reynaldo
Chris Katko

it's funny how hard it is on windows.

on linux it's literally

git clone
cd build
cmake ..
make

and 1/4th of that was changing a directory.

Dizzy Egg

Yep, using your MingW and defining -DALLEGRO_STATICLINK worked fine for me using your binaries.

@takis76 - I suggest using the MingW files Edgar posted, should be able to build without issue.

takis76

Well I got confused a little.

But first I download the MinGw64 from the link Edgar Reynaldo gave. It is MinGw 11.2
Then In my linker options I changed the option:

-lallegro_monolith-debug-static to -lallegro_monolith-static

I renamed the MinGw64 to MinGw.
I recompiled one simple hello world example.

And it run. So I will keep my current Allegro5 directory with the precompiled libraries.
And I will keep and this MimGw 11.2

Everything I knew back In allegro 4.2 have changed and I need to relearn everything again.

Of course I didn't manage to compile the Allegro from the source.
Also I do not have the source code of the Examples.

At least where do I will find the source code of the examples of version 5.2.7.1 and where do I will find some Allegro Tutorials.

It is something instead I am not able to make any Allegro game at all.
Thank you.

Chris Katko

I'm confused. Did you get Allegro up and running or not?

You can compile games, examples and everything, even with the "precompiled binaries" option.

Though I'd just suggest getting Visual Studio (it's free) and it's literally a one liner to get the NuGet packages of Allegro.

takis76 said:

Of course I didn't manage to compile the Allegro from the source.
Also I do not have the source code of the Examples.

At least where do I will find the source code of the examples of version 5.2.7.1 and

Source of all the examples are all on git.

https://github.com/liballeg/allegro5/tree/master/examples

You can download them all, or just look at them online.

Quote:

where do I will find some Allegro Tutorials.

https://github.com/liballeg/allegro_wiki/wiki/Allegro-Vivace

Quote:

It is something instead I am not able to make any Allegro game at all.

I don't understand what this means. ???

takis76

Hehe!!

<quote name="Chris Katko" "">It is something instead I am not able to make any Allegro game at all.</quote>

I mean instead not able to do nothing, at least I managed to compile something from the precompiled libraries. I compiled some source code but not the Allegro source code itself.

And thank you very much for your help you provided. And there are many other things now I will need to learn.

I am encountering and another one problem.
when I am typing something and the code autocomple presents the small menu with suggested codes when I am choosing a code from the menu, always it selects the first one.

Code Autocomplete

For example you type al_ and the suggested code menu appears.
And if for example you choose something from the list you highlight it and you click on it with the mouse (In this case let's say I will select "al_add_timer_count", it always selects the first from the list "al_acknowledge_drawing_halt" or other times selects nonsense or pastes something from my clipboard or the last typed command.

How do I will fix this problem?

Thank you.

Edgar Reynaldo

Try a more recent version of CodeBlocks - 20.03 is the latest stable version. But you can also download the nightly compiled version of CodeBlocks too, which is the cutting edge release version from GIT.

takis76

I am already have the 20.03 version.
Where can I find this nightly compiled version of Codeblocks?
Is there any newer one?

I found this link:
https://forums.codeblocks.org/index.php/topic,24794.0.html

Well, I downloaded and works nice. The bug with code autocomplete I think was fixed.
I did a quick test. when you choose some command from the list it selects the highlighted one correctly.

But Encountering problems, the IDE sometimes crash or becomes unresponsible.

I have another one question.

It is language related question and I want to check my C++ knowledge.

As I know if I will place variables at the top of the source code outside of the main() function these variables should be global to all scope.

I placed all allegro variables at the top (I mean not before the #include header files).

Let's say these:

#SelectExpand
1ALLEGRO_DISPLAY * display; 2ALLEGRO_EVENT_QUEUE *event_queue; 3ALLEGRO_EVENT event; 4ALLEGRO_TIMER *timer; 5ALLEGRO_FS_ENTRY *entry; 6ALLEGRO_FONT *font01; 7ALLEGRO_BITMAP *mouse_pointer_hand = NULL;

And I have one project with multiple source codes:

Draw_Interface.cpp
Load_Data.cpp
main.cpp
Prototypes.cpp

The source code "Prototypes.cpp" declares all the functions that the game will have.

#SelectExpand
1int Load_Data(); 2void Draw_Interface();

Because I have 2 functions the Load_Data() and the Draw_Interface() in separated files inside the project. I do not want to have one huge source code and I would like
to manage my whole project in multiple smaller source code files.

The file "Load_Data.cpp" contains this code:

#SelectExpand
1int Load_Data(void) 2{ 3font01 = al_load_font("Lbrite.ttf",16,0); 4mouse_pointer_hand = al_load_bitmap("Hand.png"); 5return 0; 6}

This code it loads some game data, in my example I am loading one font and one hand image that I will use it as a mouse pointer for the game.

The file "Draw_Interface.cpp" contains this code:

#SelectExpand
1void Draw_Interface() 2{ 3al_draw_text(font01,al_map_rgb(255,0,0),100,100,0,"Hello"); 4al_draw_bitmap(mouse_pointer_hand, 150, 150,0); 5}

This just draws a text on the screen and this mouse pointer on the screen too not yet on the mouse (I do not know the mouse position functions yet).

After the regular headers at the top of the source code of main.cpp I added and this:

#include "Prototypes.cpp"

which it will be called to declare my functions something like a prototype constructor of the functions because the program will need to know if they are exist and when I call them the source code will find them.

The code compiles correctly.
And I run it, but I have error:

Draw_Interface.cpp|11|error: 'font01' was not declared in this scope
Draw_Interface.cpp|12|error: 'mouse_pointer_hand' was not declared in this scope

Load_Data.cpp|13|error: 'font01' was not declared in this scope
Load_Data.cpp|14|error: 'mouse_pointer_hand' was not declared in this scope

These variables were initialized at the top of the source code outside of the main() function and they should be accessible by whole scope, they should be global.

Why my separated source files can't see them?

Edgar Reynaldo

Global variables are generally frowned upon, but can be a good way to get going. The main danger is that they are global, and they can be changed by multiple modules.

To make a variable accessible outside it's source file, you must declare it as 'extern' in the header.

Example :
Header.h

extern int global_int;

Then it must be defined in exactly one source module :

Source.cpp

#include "Header.h"

int global_int = 0;

Then any source module that wants access to global_int must include Header.h .

To make a function accessible, you just need to include the header that declares the function prototype. Then you define the function in a single source module.

CB Nightlies can be unstable sometimes, read the release thread for more info.

I'm using 20.03 and it autocompletes allegro functions fine for me.

takis76

Well,
I created one header file with name "Variables.h"

#SelectExpand
1#ifndef HEADER_B4C03ECCD95CBCD7 2#define HEADER_B4C03ECCD95CBCD7 3 4 5 extern ALLEGRO_DISPLAY * display; 6 extern ALLEGRO_EVENT_QUEUE *event_queue; 7 extern ALLEGRO_EVENT event; 8 extern ALLEGRO_TIMER *timer; 9 extern ALLEGRO_FS_ENTRY *entry; 10 extern ALLEGRO_FONT *font01; 11 extern ALLEGRO_BITMAP *mouse_pointer_hand = NULL; 12 13 extern int running; 14 15#endif // header guard

The header guards added automatically even if I will remove them. (I do not know why do they added).

I included the "Variables.h" everywhere.
In the "main.cpp"
In the "Draw_Interface.cpp"
And in the "Load_Data.cpp"

I changed the "Prototypes.cpp" to "Prototypes.h" and I included it only in the main.cpp

The "Variables.h" Included everywhere and the "Prototypes.h" is included to "main.cpp" only.

It compiled and now there is an error: ld returned 1 exit status
And I can't find where this error is and debugger is not showing in which line this error generates.

Edgar Reynaldo

You declared them as extern in the header, which is correct, but did you also define them somewhere and initialize them?

takis76

What extra definition of these ALLEGRO variables do I need. Don't they defined in "Variables.h"?

About initialization my "main.cpp" source code is this:

#SelectExpand
1#include <stdio.h> 2#include <allegro5/allegro.h> 3#include <allegro5/allegro_image.h> 4#include <allegro5/allegro_physfs.h> 5#include <allegro5/allegro_font.h> 6#include <allegro5/allegro_native_dialog.h> 7#include <physfs.h> 8 9#include "Variables.h" 10#include "Prototypes.h" 11 12 13int main() 14{ 15 mouse_pointer_hand = NULL; 16 17 18 al_init(); 19 al_init_native_dialog_addon(); 20 al_install_keyboard(); 21 22 23 display = al_create_display(1024, 768); 24 al_clear_to_color(al_map_rgb(100, 0, 0)); 25 event_queue = al_create_event_queue(); 26 timer = al_create_timer(1.0 / 60.0); 27 28 al_register_event_source(event_queue, al_get_keyboard_event_source()); 29 al_register_event_source(event_queue, al_get_display_event_source(display)); 30 31 while (true) 32 { 33 al_wait_for_event(event_queue, &event); 34 35 if (event.type == ALLEGRO_EVENT_KEY_DOWN) 36 { 37 if (event.keyboard.keycode == ALLEGRO_KEY_ESCAPE) { return 0; } 38 } 39 if (event.type == ALLEGRO_EVENT_DISPLAY_CLOSE) { return 0; } 40 41 42 } 43 44 45return 0; 46}

Edgar Reynaldo
Variables.cpp

#include "Variables.h"

ALLEGRO_DISPLAY * display = 0;
ALLEGRO_EVENT_QUEUE *event_queue = 0;
ALLEGRO_EVENT event;
ALLEGRO_TIMER *timer = 0;
ALLEGRO_FS_ENTRY *entry = 0; 
ALLEGRO_FONT *font01 = 0;
ALLEGRO_BITMAP *mouse_pointer_hand = NULL;
int running = 0;

DanielH

Declaration is not the same as definition

Declaring makes them visible to the compiler but they are not actually there until they are defined.

You are declaring them in the header, but never defining them.

Just some thoughts: Do not use global variables and do some error checking

takis76

You mean I didn't give them an initial value.
I will create another one module with name "Init_Variables.cpp" for the initializations.

"Init_Variables.cpp"

#SelectExpand
1#include <stdio.h> 2#include <allegro5/allegro.h> 3#include <allegro5/allegro_image.h> 4#include <allegro5/allegro_physfs.h> 5#include <allegro5/allegro_font.h> 6#include <physfs.h> 7#include <string.h> 8 9#include "Variables.h" 10 11int Init_Variables() 12{ 13 14 display = 0; 15 event_queue = 0; 16 timer = 0; 17 fs_entry = 0; 18 font01 = 0; 19 mouse_pointer_hand = NULL; 20 21 running=1; 22 23return 0; 24}

The <Prototypes.h> was updated:

#SelectExpand
1#ifndef HEADER_C37A702D3435D66F 2#define HEADER_C37A702D3435D66F 3 4int Load_Data(); 5void Draw_Interface(); 6int Init_Variables(); 7 8#endif // header guard

My "main.cpp" code does this:

#SelectExpand
1#include <stdio.h> 2#include <allegro5/allegro.h> 3#include <allegro5/allegro_image.h> 4#include <allegro5/allegro_physfs.h> 5#include <allegro5/allegro_font.h> 6#include <allegro5/allegro_native_dialog.h> 7#include <physfs.h> 8 9#include "Variables.h" 10#include "Prototypes.h" 11 12 13int main() 14{ 15 16 Init_Variables(); 17 18 19 al_init(); 20 al_init_native_dialog_addon(); 21 al_install_keyboard(); 22 23 24 display = al_create_display(1024, 768); 25 al_clear_to_color(al_map_rgb(100, 0, 0)); 26 event_queue = al_create_event_queue(); 27 timer = al_create_timer(1.0 / 60.0); 28 29 al_register_event_source(event_queue, al_get_keyboard_event_source()); 30 al_register_event_source(event_queue, al_get_display_event_source(display)); 31 32 while (true) 33 { 34 al_wait_for_event(event_queue, &event); 35 36 if (event.type == ALLEGRO_EVENT_KEY_DOWN) 37 { 38 if (event.keyboard.keycode == ALLEGRO_KEY_ESCAPE) { return 0; } 39 } 40 if (event.type == ALLEGRO_EVENT_DISPLAY_CLOSE) { return 0; } 41 42 43 } 44 45 46return 0; 47}

It complains about the "Prototypes.h"

Prototypes.h.gch: file not recognized: File format not recognized
collect2.exe: error: ld returned 1 exit status

What's wrong with my "Prototypes.h"? File format not recognized? It is a normal text file with source code.

Dizzy Egg

Prototypes.h.gch

That should be Prototypes.h

Not sure what .gch is?

DanielH
takis76 said:

You mean I didn't give them an initial value.

Not quite. You need to define your variables.

#SelectExpand
1#ifndef HEADER_B4C03ECCD95CBCD7 2#define HEADER_B4C03ECCD95CBCD7 3 4 // declarations 5 extern ALLEGRO_DISPLAY * display; 6 extern ALLEGRO_EVENT_QUEUE *event_queue; 7 extern ALLEGRO_EVENT event; 8 extern ALLEGRO_TIMER *timer; 9 extern ALLEGRO_FS_ENTRY *entry; 10 extern ALLEGRO_FONT *font01; 11 extern ALLEGRO_BITMAP *mouse_pointer_hand = NULL; 12 13 extern int running; 14 15#endif // header guard

Somewhere GLOBALLY you need to DEFINE them. You can choose to initialize then to null or not but they must be DEFINED.

#SelectExpand
1 2#include <stdio.h> 3#include <allegro5/allegro.h> 4#include <allegro5/allegro_image.h> 5#include <allegro5/allegro_physfs.h> 6#include <allegro5/allegro_font.h> 7#include <physfs.h> 8#include <string.h> 9 10#include "Variables.h" 11 12// definitions 13ALLEGRO_DISPLAY * display; 14ALLEGRO_EVENT_QUEUE *event_queue; 15ALLEGRO_EVENT event; 16ALLEGRO_TIMER *timer; 17ALLEGRO_FS_ENTRY *entry; 18ALLEGRO_FONT *font01; 19ALLEGRO_BITMAP *mouse_pointer_hand; 20 21int running; 22 23int Init_Variables() 24{ 25 26 display = 0; 27 event_queue = 0; 28 timer = 0; 29 fs_entry = 0; 30 font01 = 0; 31 mouse_pointer_hand = NULL; 32 33 running=1; 34 35return 0; 36}

takis76

Why do I need to write my variables code 2 times.
Putting them in the "Variables.h" module they should be Defined.
But if I will have lots of variable and I do not want to have bulk them at the top of my main source code and have them inside a module? (For a code management).

Also I removed this "Prototypes.h" it was complained and I put them on the top of the main source code too. But if I like to have my Prototype functions inside a separated module file too? why the compiler is complaining about the file format in not recognized?

Put everything in one single huge source code may will work but I do not want something like that.

The "Prototypes.h" were removed.

The new "main.cpp" code it looks like this now:

#SelectExpand
1#include <stdio.h> 2#include <allegro5/allegro.h> 3#include <allegro5/allegro_image.h> 4#include <allegro5/allegro_physfs.h> 5#include <allegro5/allegro_font.h> 6#include <allegro5/allegro_native_dialog.h> 7#include <physfs.h> 8 9#include "Variables.h" 10 11 ALLEGRO_DISPLAY * display; 12 ALLEGRO_EVENT_QUEUE *event_queue; 13 ALLEGRO_EVENT event; 14 ALLEGRO_TIMER *timer; 15 ALLEGRO_FS_ENTRY *fs_entry; 16 ALLEGRO_FONT *font01; 17 ALLEGRO_BITMAP *mouse_pointer_hand; 18 19 int running; 20 21 int Load_Data(); 22 void Draw_Interface(); 23 int Init_Variables(); 24 25int main() 26{ 27 28 Init_Variables(); 29 30 31 al_init(); 32 al_init_native_dialog_addon(); 33 al_install_keyboard(); 34 35 36 display = al_create_display(1024, 768); 37 al_clear_to_color(al_map_rgb(100, 0, 0)); 38 event_queue = al_create_event_queue(); 39 timer = al_create_timer(1.0 / 60.0); 40 41 al_register_event_source(event_queue, al_get_keyboard_event_source()); 42 al_register_event_source(event_queue, al_get_display_event_source(display)); 43 44 while (true) 45 { 46 al_wait_for_event(event_queue, &event); 47 48 if (event.type == ALLEGRO_EVENT_KEY_DOWN) 49 { 50 if (event.keyboard.keycode == ALLEGRO_KEY_ESCAPE) { return 0; } 51 } 52 if (event.type == ALLEGRO_EVENT_DISPLAY_CLOSE) { return 0; } 53 54 55 } 56 57 58return 0; 59}

Of course the "Variables.h" module still exists.

This was run, but I thought placing the variables in a header file they get declared once.
Now I wrote the variables 2 times one with the extern operator and one without.

UPDATE and STRANGE

I deleted my "Prototypes.h" file and I created a new one and I put the function prototype code and now it run without complain the file format is not recognized.

???

Another Problem:

al_draw_text(font01,al_map_rgb(255,0,0),0,0,  0,"Hello");

Presents nothing.

My "Load_Data.cpp" checks if the file was loaded.

#SelectExpand
1#include <stdio.h> 2#include <allegro5/allegro.h> 3#include <allegro5/allegro_image.h> 4#include <allegro5/allegro_physfs.h> 5#include <allegro5/allegro_font.h> 6#include <allegro5/allegro_native_dialog.h> 7#include <physfs.h> 8#include <string.h> 9 10#include "Variables.h" 11 12int Load_Data(void) 13{ 14 15 font01 = al_load_font("Lbrite.ttf",24,0); 16 if (!font01) 17 { 18 //int al_show_native_message_box(ALLEGRO_DISPLAY *display,char const *title, char const *heading, char const *text,char const *buttons, int flags) 19 al_show_native_message_box(display,"Adventure Maker","Warning","The file 'Lbrite.ttf' wasn't found",NULL,0); 20 } 21 22 mouse_pointer_hand = al_load_bitmap("Hand.png"); 23 if (!mouse_pointer_hand) 24 { 25 al_show_native_message_box(display,"Adventure Maker","Warning","The file 'Hand.png' wasn't found",NULL,0); 26 } 27 28return 0; 29}

I managed to place my mouse pointer hand on the mouse position x and y now I am looking how to make the color(255,0,255) transparent.

DanielH

Twice because declaration != definition.

Just like function declarations and definitions.

// declaration
int myfunc();

// definition
int myfunc()
{
    return 0;
}

Declarations are only needed if you plan to share the variables between multiple source files. Otherwise you don't need to declare them and won't need to write them twice.

takis76

I found how to draw transparent images, but I will need to run the

al_convert_mask_to_alpha(mouse_pointer_hand, al_map_rgb(255, 0, 255));

Each time I will need to draw an image. Is there any global function that will convert the color rgb(255,0,255) to transparent once in the whole program at once.
I remember there was a function set_image_colorkey in the old Allegro versions back in 4.2.0 and you set the transparent color globally to everything.

The manual is not good. You can't find things easily. Everything I found so far was from your help and searching in Google. You will say search in Google again, I am searching but I do both, I first search in Google and if I will not find the answer then I ask you to bother you as less as I can.

Practically I am going to create a small program that will have all the basic functions will be needed to create a game to have it as a working source code example and then copy the code from this program to design my future games.

;D

UPDATE
I fixed the error that the text wasn't present.

It needed an additional header file. The #include <allegro5/allegro_font.h> wasn't enough. It needs and #include <allegro5/allegro_ttf.h>

And it needs and the "al_init_ttf_addon();" too.

The global transparent color remains until the next question.

DanielH

You could set the transparency to the image itself before it is saved in the folder. I do that so I don't have to bother with al_convert_mask_to_alpha. Use an image format that handles transparencies like PNG and make sure your image editor can save transparencies.

takis76

So, you suggest to save the images transparent from the paint program. So there is not a way to set a global transparent color like we did in the past.

I have another one question about strings in C++ (I will check my c++ knowledge again).

I am using the "#include <iostream>" to activate the strings.

When I want to define a string variable I use this code:

#include <iostream>
using namespace std;

string is_running = "No";

blah blah Allegro initialization the code in main.cpp

I have defined and the variable as extern

extern string is_running;

And when I am trying to draw some string text

al_draw_text(font01,al_map_rgb(255,0,0),100,120,0, is_running);

I have a new error:
'string' does not name a type; did you mean 'stdin'?

I make the varialble is_running to be a global string. I thing. (Because was defined in "Variables.h" and of course initialized after was defined in "Init_Variables.cpp" as usual.

The error appears in "extern string is_running;" so the variable is_running wasn't defined and then another error says:

error: 'is_running' was not declared in this scope.

DanielH

No, there is no function to set transparent colors (Magic Pink) like in Allegro 4.

You have 2 options: Either save the transparency in the file itself or pick a color like magic pink and use al_convert_mask_to_alpha to set the alpha channel to transparent.

For the strings, did you include the iostream header in the source file so the source file knows what a string is? You should be using the string header file <string> to activate strings. Just because <iostream> also includes it you got away with it.

#include <string>

Also, remember Allegro is written in C so you need to use C style strings. You can use the string function cstr() to convert it to a C style string.

al_draw_text(font01,al_map_rgb(255,0,0),100,120,0, is_running.cstr());

If you insist on using global variables, put all "extern" declarations in your header. In one (and only one) source file you need to define them. Then you can use your global anywhere. Just make sure to include your variable header file in each source file you want to use those variables.

takis76

Using:

extern string is_running;

In my "Variables.h"

And initializing it:

string is_running = "No";

Drops an error In the "extern string is_running;"

'string' does not name a type; did you mean 'stdin'?|

I have included both <iostream> and <string> in all my source code modules.

#include <iostream>
#include <string>

DanielH
using namespace std;

// or use

std::string is_running = "No";

Do this for both the declaration and definition.

If you do this in the header, that will be sufficient because you are including the header. Am I correct?

// Variables.h
#include <string>
using namespace std;

extern string is_running;

// source file
#include "Variables.h"

string is_running = "No";

Dizzy Egg

Meh (I've had a few cans)

takis76

Well I removed the <iostream.h>

I added "using namespace std;" to all modules except in the "Prototypes.h"

And there was an error in this line:

al_draw_text(font01,al_map_rgb(255,0,0),100,120,0, is_running.cstr() );

I should use is_running.c_str() instead of is_running.cstr();

If I want to do the same with an integer variable?
The "is_running" was a string variable, if for example I have a float or an integer, can I make a cast? or convert the float or the integer to string?

Trying this is not working

running.cstr();

error: request for member 'c_str' in 'running', which is of non-class type 'int'|

Trying this:

(string)running;

This doesn't seem to work too.

error: no matching function for call to 'std::__cxx11::basic_string<char>::basic_string(int&)'|

The running variable was defined as "int running;"
I have 2 variables 1 with name is_running which was string (we fixed this) and the running which is integer.

In the past I remember I used cast.

Chris Katko

cast says to the compiler "this variable is of a different type than you think so treat it as I say it is". It does not convert variables binary representation. So a string holding the character "1" is completely different in binary from the integer variable=1 for example.

int x = 1; 
string x = "1"; //completely different in memory! 

Semicolons are only used to end statements. A function call doesn't have any statements so it doesn't need any semicolons.

If you want to draw text, use al_draw_printf (for Allegro 5) or textprintf_ex (for allegro 4)

https://www.allegro.cc/manual/5/al_draw_textf
https://liballeg.org/stabledocs/en/alleg018.html#textprintf_ex

These are functions that take text, formatted like the normal printf function, and draw it to the screen.

You cannot send an integer variable to a printf function. It is expecting a string, that is formatted a special way that includes instructions on how to print variables.

see here:

https://www.cplusplus.com/reference/cstdio/printf/

So to send a numeric variable out, you send it inside of a string exactly the same way you'd use normal printf for printing to the console.

printf("my variable is equal to %d.\n", 10); 
// %d means print an integer here
// \n is a special code for add a newline

prints out

my variable is equal to 10.

It saw "%d" in the string and realized that was where a integer should be, so it then looked for the next argument which happened to equal 10, and then wrote "10" into the string.

Allegro printout functions work the same way as this is the standard way to write strings in C (and often times in C++). the "printf style" has been used in many programming languages.

What it looks like you were attempting to do, and the compiler was trying to help was this:

printf(10);
// stdio.h:332:43: note: expected ‘const char * restrict’ but argument is of type ‘int’

But printf doesn't know what 10 means. You could print the value 10 in many ways. As decimal. As binary. As hexidemical. As a ASCII character. It wants a string that specifies how to format the output.

more printf stuff:

    int X = 10;

    printf("my constant is equal to %d\n", 15); // a constant into a string
    printf("my variables are equal to %d, %d, %d\n", X, 20, 30); // multiple variables
    printf("my variables are equal to %d, %x, %p\n", X, X, X); //use same variable MULTIPLE TIMES but with different formatting

prints out:

my constant is equal to 10
my variables are equal to 10, 20, 30
my variables are equal to 10, a, 0xa

// A is hexidecimal for 10
// 0xa is because it's told to print the value 10 as if it was a pointer 

What you did when you called cstr on a string was create a c-style string and pass it to the Allegro function. That works. However, if you want a integer? You have to place it inside of a string. With a printf style function (or the C++ equivalent) for strings... called... sprintf ("string printf"). Or any Allegro function that mimics printf style like the ones I mentioned above, they do that for you. But the reason you cannot call cstr on an integer is because it's just that. An integer. It doesn't have any methods to call. cstr is a method only for the string class.

This post feels all over the place, but you've got a lot of missing fundamentals in your knowledge of C/C++ (which is okay, it's just they all need addressed to explain what's wrong).

takis76

Thank you very very much. :)

This worked excellent.

al_draw_text(font01,al_map_rgb(255,0,0),70,120,0, is_running.c_str() );
al_draw_textf(font01,al_map_rgb(0,255,255),70,140,0, "%d",running );
al_draw_textf(font01,al_map_rgb(0,255,255),70,160,0, "%s",is_running.c_str() );

Then I will try to load some music and sound in the next and if I will have any problem I will post here and after I will load some sound I will try this PhysFS addon.

Learning the Allegro, I will refresh my C++. (Yes I have many missing fundamentals in C++ and even some books do not cover everything) , but when I was using the C++ last time was with DJGPP and DOS (With Allegro 4.2.0 or may I will not using C++ at all may it was C no C++) these things worked (The example with cast I mentioned) and before the DJGPP I was programmed with C++ many years ago before DJGPP in 90s was with Borland C++, that's I have to say Borland C++ had the best manual, you pressed F1 on the command or function and you had an instant example, now F1 does nothing and even the code autocompletion presents a huge list of unrelated commands. Many things were changed.

And all C++ versions are not the same.

Thread #618576. Printed from Allegro.cc