The Allegro Wiki is migrating to github at https://github.com/liballeg/allegro_wiki/wiki

KDevelop

From Allegro Wiki
Jump to: navigation, search
Merge-arrows.gif
It has been suggested that this article or section be merged with Using Allegro with autoconf/KDevelop. (Discuss)


Background

KDevelop is a popular IDE often bundled with Linux installations. The K stands for KDE, which is the graphical environment it was originally intended for, but it also works fine on the GNOME environment.

Setting up a Project

This section includes information copied from Josh1billion's "Allegro on Fedora (Linux) with KDevelop" guide originally posted on the Allegro.cc forums ( it can be found here: http://www.allegro.cc/forums/thread/592235 ). The first part of that guide has been left out of this article because it focuses on Allegro installation (for Fedora 7).

Part 1: Starting a new project in KDevelop

Step 1. Run "KDevelop: C/C++". If you're using GNOME, it is located in Applications->Programming. Notice that there are many different versions of KDevelop listed there-- make sure you use "C/C++", not "KDE/C++"

Step 2. Under the Project menu, go to New Project. Under the C++ category, choose Simple Hello world program, as shown in this screenshot:

Newprojectkq6.png

Type in a name for the project ("helloworld" for example), etc.

Part 2: Entering the Code

Step 1. Once you have the code on-screen, remove it and copy+paste this ALL of this (including END_OF_MAIN()) over it instead:

<HighlightSyntax language="cpp">

  1. include <allegro.h>

int main(void) {

   allegro_init();
   set_gfx_mode(GFX_AUTODETECT_WINDOWED, 640, 480, 0, 0);
   install_keyboard();
   textout_ex(screen, font, "Hello World!", 1, 1, 10, -1);
   while(!key[KEY_ESC]);
   allegro_exit();
   return 0;

} END_OF_MAIN() </HighlightSyntax>

Part 3: Linking the Allegro libraries into the project

Step 1. On the way-right edge of the KDevelop window, you'll find Documentation, Code Snippets, and Automake Manager listed vertically. Odd that they would be hidden over there.. hard to find if you're not looking just right. Anyway, click the "Automake Manager" tab to bring up the automake manager side panel. In the bottom pane of the side panel, you will see two entries: "(Header in noinst)" and "[name of your project]". Right-click your project's name (shown in the Step 5 screenshot as "utd_test" because that's my project's name), and choose Options.

Step 2. Go to the Libraries tab. Now, we're going to click Add and type in the filename of the Allegro library. But before we do that, we have to know what the filename of the library is. So open up a terminal and type this command, the same command we typed earlier: allegro-config --libs

It should output something like this, a list of Allegro libraries. -L/usr/lib -Wl,--export-dynamic -lalleg-4.2.1 -lalleg_unsharable

Step 3. Copy and paste the name of the library that looks like "-lalleg-4.2.1" into that dialog that pops up when you press the Add button. Depending on your version, it could be -lalleg-4.3 or something else, so don't use what mine says; use what yours said when you typed the above command, instead. The other libraries listed seem irrelevant and link fine for me without, but if you later run into problems compiling/linking your project, try copying and pasting them in there as well. Others have recommended pasting in the entire line that "alleg-config --libs" outputs, but for me that produces an error with the "-Wl,--export-dynamic" part which I later had to remove from there. Click "OK" on all the windows when you're ready and proceed...

The libraries should now be linked, so we'll build the project and run it.

Part 4: Building the project and executing it

Step 1. In the main KDevelop window, on the menu, go to Build and choose Build Project (or press F8). The project should compile and link as normal, and say Success when done. Good! Now you can run the game by going to Build->Execute Program (or press Shift+F9).

Librariesjq9.png