By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,640 Members | 2,110 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,640 IT Pros & Developers. It's quick & easy.

Trying to compile a program that uses the allegro library

P: 1
hi there,

as i said i'm trying to compile a simple program that uses allegro, it's a small thing, indeed my goal was just to start using allegro, but until now i'm unable even to compile my simple program.

that's the program (i named it alle.c):

Expand|Select|Wrap|Line Numbers
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. #include <allegro.h>
  5.  
  6. #define MAX_X        800
  7. #define MAX_Y        600
  8. #define V_MAX_X        0
  9. #define V_MAX_Y        0
  10. #define COLOR_BITS    8
  11.  
  12. int inicia(void);
  13. void principal(void);
  14. void finaliza(void);
  15.  
  16. int main (void)
  17. {
  18.     if (!inicia())
  19.     {
  20.         finaliza();
  21.         return -1;
  22.     }
  23.  
  24.     principal();
  25.  
  26.     finaliza();
  27.     return 0;
  28. }
  29. END_OF_MAIN();
  30.  
  31. int inicia (void)
  32. {
  33.     allegro_init();
  34.  
  35.     install_keyboard();
  36.  
  37.     set_color_depth(COLOR_BITS);
  38.     if (set_gfx_mode(GFX_AUTODETECT, MAX_X, MAX_Y, V_MAX_X, V_MAX_Y) < 0)
  39.     {
  40.         printf("Erro ao inicializar o modo grafico.\n");
  41.         return (FALSE);
  42.     }
  43.  
  44.     set_palette(desktop_palette);
  45.  
  46.     return (TRUE);
  47. }
  48.  
  49. void principal (void)
  50. {
  51. }
  52.  
  53. void finaliza (void)
  54. {
  55.     allegro_exit();
  56. }
  57.  
i tried to compile it using gcc:
gcc -I/usr/include/ -o jogo alle.c -Wall -lalleg

but i received that error message:
/usr/bin/ld: cannot find -lalleg

I suspect that the error concerns to a missing library, but i'm not sure.

Can you confirm me that it was in fact a missing library and, if that's the case, wich library should i install, because i have no idea about what it is?

thanks
Feb 8 '07 #1
Share this Question
Share on Google+
1 Reply


AdrianH
Expert 100+
P: 1,251
i tried to compile it using gcc:
gcc -I/usr/include/ -o jogo alle.c -Wall -lalleg

but i received that error message:
/usr/bin/ld: cannot find -lalleg

I suspect that the error concerns to a missing library, but i'm not sure.

Can you confirm me that it was in fact a missing library and, if that's the case, wich library should i install, because i have no idea about what it is?

thanks
Your suspicions are correct. Here is copy from the gcc info pages. I've wrapped it in a html tag to keep the message in preformatted form, otherwise I would have put html pre tags around it.
[html]
`-lLIBRARY'
`-l LIBRARY'
Search the library named LIBRARY when linking. (The second
alternative with the library as a separate argument is only for
POSIX compliance and is not recommended.)

It makes a difference where in the command you write this option;
the linker searches and processes libraries and object files in
the order they are specified. Thus, `foo.o -lz bar.o' searches
library `z' after file `foo.o' but before `bar.o'. If `bar.o'
refers to functions in `z', those functions may not be loaded.

The linker searches a standard list of directories for the library,
which is actually a file named `libLIBRARY.a'. The linker then
uses this file as if it had been specified precisely by name.

The directories searched include several standard system
directories plus any that you specify with `-L'.

Normally the files found this way are library files--archive files
whose members are object files. The linker handles an archive
file by scanning through it for members which define symbols that
have so far been referenced but not defined. But if the file that
is found is an ordinary object file, it is linked in the usual
fashion. The only difference between using an `-l' option and
specifying a file name is that `-l' surrounds LIBRARY with `lib'
and `.a' and searches several directories.

...

`-LDIR'
Add directory DIR to the list of directories to be searched for
`-l'.
[/html]

What this says is that you do not have a library named liballeg.a in the library path. If it is in the current directory use -L. to search the current directory. That is -L dot. Otherwise, specify where the library file is and make sure it is there.

Hope this helps.


Adrian
Feb 8 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.