Allegro.cc - Online Community

Allegro.cc Forums » Installation, Setup & Configuration » Cannot compile simple allegro prog

Credits go to Arthur Kalliokoski, OnlineCop, Thomas Fjellstrom, and Trent Gamblin for helping out!
This thread is locked; no one can reply to it. rss feed Print
Cannot compile simple allegro prog
HaitiBoy
Member #11,060
June 2009

Hello,
I am a newbie to Allegro and c++.
I have installed allegro 4.2.2 using MacPorts:

%% sudo port install allegro

I am trying to write a simple program from Allegro tutorial. I have just main.cpp. Here is the code:

#include <allegro.h>

int main(){
allegro_init();
install_keyboard();
set_gfx_mode(GFX_AUTODETECT, 640, 480, 0, 0);

readkey();

return 0;
}

END_OF_MAIN();

I do not use XCode or Eclipse. I use Smultron.
I cannot even compile it:

To compile I have tried this:

%% g++ -o main main.cpp
and
%% g++ -o main main.cpp -L /opt/local/include -l allegro.h

Anyway I get this:

main.cpp:1:21: error: allegro.h: No such file or directory
main.cpp: In function ‘int main()’:
main.cpp:4: error: ‘allegro_init’ was not declared in this scope
main.cpp:5: error: ‘install_keyboard’ was not declared in this scope
main.cpp:6: error: ‘GFX_AUTODETECT’ was not declared in this scope
main.cpp:6: error: ‘set_gfx_mode’ was not declared in this scope
main.cpp:8: error: ‘readkey’ was not declared in this scope
main.cpp: At global scope:
main.cpp:13: error: expected constructor, destructor, or type conversion before ‘;’ token

Any help is appreciated. ??? ???

Thanks

Arthur Kalliokoski
Second in Command
February 2005
avatar

I believe your -I option is supposed to point to the path where allegro.h is.

[EDIT]
not fully awake yet.

They all watch too much MSNBC... they get ideas.

Thomas Fjellstrom
Member #476
June 2000
avatar

Ok, you actually want to compile like so:

g++ -o main main.cpp `allegro-config --libs`

Notice those are backticks (`) not single quotes (').

That said, -L is to tell gcc which folder to add to the linker path (where to look for libraries), and -l is to add lib to link to: -lsomelib

--
Thomas Fjellstrom - [website] - [email] - [Allegro Wiki] - [Allegro TODO]
"If you can't think of a better solution, don't try to make a better solution." -- weapon_S
"The less evidence we have for what we believe is certain, the more violently we defend beliefs against those who don't agree" -- https://twitter.com/neiltyson/status/592870205409353730

HaitiBoy
Member #11,060
June 2009

ok,
I have tried

%% g++ -o main main.cpp `allegro-config --libs`

I got the same thing.

Thanks for your help

Trent Gamblin
Member #261
April 2000
avatar

Did you build allegro? Did you run "make install" afterwards?

OnlineCop
Member #7,919
October 2006
avatar

MacPorts does NOT install the header files from my experiences. It installs the libraries only (to run others' precompiled games). You will actually need to download and install allegro's sources yourself and compile them.

I tried MacPorts to do the same thing. It failed. :P

HaitiBoy
Member #11,060
June 2009

Thanks guys, I have uninstalled MacPorts version of Allegro and installed version from the web site and it works!

Thanks for your help.
:D

Go to: