Вопрос

I'm trying to set up Allegro to work with MinGW in Geany in Windows. But I keep running into errors (I assume linker errors). Here's what I've done so far:

  • I already had Geany and MinGW installed.

  • I downloaded Allegro 5 from http://www.allegro.cc/files/

  • I chose Allegro MinGW 4.6.2 zip under Windows Binaries

  • I unzipped the file (allegro-5.0.7-mingw-4.6.2)

It contained 3 folders; lib, bin, and include.

I then copied the folders into my MinGW installation. More specifically, I merged the lib, bin, and include folders from Allegro with the lib, bin, and include in my MinGW installation.

After that I set up my build commands in Geany as follows:

Compile: g++ -O0 -g3 -Wall -c -o"%e.o" "%f"

Build: g++ -o"%e" ./%e.o -Lalleg

Execute: "./%e"

When I try to build my project I get a bunch of undefined reference errors. Any help with this would be awesome!

Это было полезно?

Решение

  1. You should use -l parameter instead of -L parameter to link with static library. -L parameter is used to input additional library paths where compiler should look for.

  2. As you can see there is no "liballeg.a" file in "allegro-5.0.7-mingw-4.6.2" folder so you are not linking at all.

  3. You don't have to copy all of those files to anywhere, but you should tell your compiler where it should look for headers and libraries by using -I and -L parameters.

Lets suppose you extracted "allegro-5.0.7-mingw-4.6.2.7z" to "allegro-5.0.7-mingw-4.6.2" folder. You have lib, inclued and bin folder. Just create in this folder a file and name it "main.cpp".

Content of main.cpp:

#include <allegro5/allegro.h>

int main(){
   al_init();

   return 0;
}

Now all you have to do is, enter to the allegro-5.0.7-mingw-4.6.2

  • compile main.cpp like this

g++ -c main.cpp -o main.o -I./include

  • link main.o with library:

g++ -o main.exe main.o -L./lib -lallegro-5.0.7-md

Now you have to configure Geany to do the same. You can omit -I and -L parameters if you pasted library and header files to proper MinGW folders.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top