Page 1 of 1

Adding the Allegro library to Code::Blocks in Ubuntu 8.04 This simple tutorial covers adding the allegro library and linking it Rate Topic: -----

#1 Nykc  Icon User is offline

  • Gentleman of Leisure
  • member icon

Reputation: 729
  • View blog
  • Posts: 8,642
  • Joined: 14-September 07

Posted 08 July 2008 - 01:40 PM

The Allegro library is a popular gaming library which was popular among Dev C++ IDE users. Now that Code::Blocks has pretty much taken over as the premiere free cross platform IDE for the C/C++ Programming language I decided to attempt to use the Allegro library with my Code::Blocks IDE and encountered some issues. After researching briefly on the internet I found a rather simple solution to my problem and decided to share it with the community.

First: Head over to the synaptic package manager and mark for install the Allegro libraries. This is easiest found using the handy search feature located conveniently atop of the package manager.

Once installed fire up Code::Blocks, this is where a little problem I encountered occurred.

Allegro is not linked up to Code::Blocks by default so in your IDE select Settings > Compiler and Debugger > Linker Settings and type the following into "Other linker options"

`allegro-config --libs --static`


Attached Image

Be sure to include the back ticks as well. That should take care of it. Not to difficult to do but seems a lot of people experienced some problems getting Allegro to work with Code::Blocks.

Now lets test Allegro out.

Open up a new file in Code::Blocks and name it something like allegroTestFile.c and enter the following code:

#include <allegro.h>

int main()
{
    //Initialize Allegro
    allegro_init();

    //Set the resolution to 640 x 480 with SAFE autodetection.
    set_gfx_mode(GFX_SAFE, 640, 480, 0, 0);

    //Install the keyboard handler
    install_keyboard();

    //Print your welcome message to the screen
    textout(screen, font, "Hello Dream.In.Code! This is my first Allegro Program", 1, 1, 10);
    textout(screen, font, "Press ESCape to quit.", 1, 12, 11);

    //Loop until escape is pressed
    while(! key[KEY_ESC])
        poll_keyboard(); 

    //Exit program
    allegro_exit();
    return 0;
}

END_OF_MAIN();



Press f9 to compile and run!
Here is an image of the final result - Enjoy!
Attached Image

Portions of this code as well as more detailed information regarding game programming with the Allegro Library can be found in Jonathon Harbour's "Game Programming All In One - 2nd Edition"

Please feel free to comment if you have any questions or concerns.

Is This A Good Question/Topic? 0
  • +

Replies To: Adding the Allegro library to Code::Blocks in Ubuntu 8.04

#2 Omen_20  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 19-February 09

Posted 19 February 2009 - 10:54 AM

I followed your instructions but when I press F9 this is my output:

sh: /home/clint/Desktop/allegro_test: Permission denied

Press ENTER to continue

I might not have installed all the needed Allegro libraries but I installed everything I could find in synaptic. Do you know what I may be missing or doing wrong?

Edit:
I still cant get your example to work but I downloaded a demo .cpp file that my professor has online. I believe it was made in Dev-C++. Anyways it works just fine and it uses Allegro. Maybe that will help with figuring out my problem. Thanks.

This post has been edited by Omen_20: 19 February 2009 - 11:21 AM

Was This Post Helpful? 0
  • +
  • -

#3 haiyun211  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 1
  • View blog
  • Posts: 58
  • Joined: 27-July 09

Posted 09 September 2009 - 07:49 PM

I know this is a old post but I really need some help I have followed your steps and when I try to compile this I get this out put:

-------------- Build: Debug in doing allegro ---------------

Compiling: main.cpp
/home/haiyun211/Documents/c++_projects/doing allegro/main.cpp: In function ‘int main()’:
/home/haiyun211/Documents/c++_projects/doing allegro/main.cpp:8: warning: ‘void textout(BITMAP*, const FONT*, const char*, int, int, int)’ is deprecated (declared at /usr/include/allegro/alcompat.h:157)
/home/haiyun211/Documents/c++_projects/doing allegro/main.cpp:8: warning: ‘void textout(BITMAP*, const FONT*, const char*, int, int, int)’ is deprecated (declared at /usr/include/allegro/alcompat.h:157)
/home/haiyun211/Documents/c++_projects/doing allegro/main.cpp:9: warning: ‘void textout(BITMAP*, const FONT*, const char*, int, int, int)’ is deprecated (declared at /usr/include/allegro/alcompat.h:157)
/home/haiyun211/Documents/c++_projects/doing allegro/main.cpp:9: warning: ‘void textout(BITMAP*, const FONT*, const char*, int, int, int)’ is deprecated (declared at /usr/include/allegro/alcompat.h:157)
Linking console executable: bin/Debug/doing allegro
obj/Debug/main.o: In function `textout':
/usr/include/allegro/alcompat.h:157: undefined reference to `_textmode'
/usr/include/allegro/alcompat.h:157: undefined reference to `textout_ex'
obj/Debug/main.o: In function `main':
/home/haiyun211/Documents/c++_projects/doing allegro/main.cpp:5: undefined reference to `_install_allegro_version_check'
/home/haiyun211/Documents/c++_projects/doing allegro/main.cpp:6: undefined reference to `install_keyboard'
/home/haiyun211/Documents/c++_projects/doing allegro/main.cpp:7: undefined reference to `set_gfx_mode'
/home/haiyun211/Documents/c++_projects/doing allegro/main.cpp:8: undefined reference to `font'
/home/haiyun211/Documents/c++_projects/doing allegro/main.cpp:8: undefined reference to `screen'
/home/haiyun211/Documents/c++_projects/doing allegro/main.cpp:9: undefined reference to `font'
/home/haiyun211/Documents/c++_projects/doing allegro/main.cpp:9: undefined reference to `screen'
/home/haiyun211/Documents/c++_projects/doing allegro/main.cpp:12: undefined reference to `poll_keyboard'
/home/haiyun211/Documents/c++_projects/doing allegro/main.cpp:11: undefined reference to `key'
/home/haiyun211/Documents/c++_projects/doing allegro/main.cpp:13: undefined reference to `allegro_exit'
collect2: ld returned 1 exit status
Process terminated with status 1 (0 minutes, 0 seconds)
12 errors, 4 warnings
 


I also tried running it as a c program and same result. Thanks in advanced.
Was This Post Helpful? 0
  • +
  • -

#4 Moriarty  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 20-February 11

Posted 07 December 2011 - 12:10 PM

I installed allegro-4.4.1 from source on Ubuntu 11.10 but the allegro programs only work inside the Code::Blocks IDE. If I run the executables from the command line I get this error:
./allg-test: error while loading shared libraries: liballeg.so.4.4: cannot open shared object file: No such file or directory

How can I fix this?

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1