3 Replies - 1746 Views - Last Post: 27 September 2010 - 05:58 PM Rate Topic: -----

#1 yanom  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 70
  • Joined: 05-April 08

Allegro graphics library freaking out on me.

Posted 25 September 2010 - 03:31 PM

I tried compiling this example program using the allegro graphics library:

#include <allegro.h>

const int scrx = 640;
const int scry = 480;

int main(int argc, char* argv[]) {
  if (allegro_init()) {
    allegro_message("Cannot initalize Allegro.\n");
    return 1;
  }

  //Set the window title when in a GUI environment
  set_window_title("Hello World");

  if (install_keyboard()) {
    allegro_message("Cannot initalize keyboard input.\n");
    return 1;
  }

  //set graphics mode, trying all acceptable depths
  set_color_depth(32);
  if (set_gfx_mode(GFX_AUTODETECT, scrx, scry, 0, 0)) {
    set_color_depth(24);
    if (set_gfx_mode(GFX_AUTODETECT, scrx, scry, 0, 0)) {
      set_color_depth(16);
      if (set_gfx_mode(GFX_AUTODETECT, scrx, scry, 0, 0)) {
        set_color_depth(15);
        if (set_gfx_mode(GFX_AUTODETECT, scrx, scry, 0, 0)) {
          allegro_message("Video Error: %s.\n", allegro_error);
          return 1;
        }
      }
    }
  }

  //set text background color to bright blue
  text_mode(makecol(0, 0, 255));

  //prints yellow "Hello World!!!" in middle of screen
  textout_centre(screen, font, "Hello World!!!", scrx/2,
                 scry/2, makecol(255, 255, 0));

  //Wait for a key to be pressed
  while (!keypressed()) {}

  return 0;
  //Allegro will automatically deinitalize itself on exit
}
END_OF_MAIN()


but it throws some crazy errors, like "undefined reference to <<something or other>>". The error log is attached. I used this makefile (command "make all"):
CC=gcc
NAME=main
FILES=main.c
LF=-lalleg

all: default

default: build

build:
    $(CC) -o $(NAME) $(FILES) $(LF)

clean:
    rm -rf *.o
    rm -rf $(NAME)

destroy:
    rm -rf ./*

Attached File(s)



Is This A Good Question/Topic? 0
  • +

Replies To: Allegro graphics library freaking out on me.

#2 Oler1s  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1395
  • View blog
  • Posts: 3,884
  • Joined: 04-June 09

Re: Allegro graphics library freaking out on me.

Posted 25 September 2010 - 04:12 PM

You aren't linking to the math and Xlib library. You could figure this out yourself, or you could use allegro-config or pkg-config to do the job. For example, gcc myfile.c -o myprogram `allegro-config --libs`.

Of course, you want to make use of your makefile, so running allegro-config --libs to get the information, and then using that information in your makefile is a smart idea.
Was This Post Helpful? 1
  • +
  • -

#3 Seta00  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 14
  • View blog
  • Posts: 84
  • Joined: 22-September 10

Re: Allegro graphics library freaking out on me.

Posted 25 September 2010 - 06:05 PM

View PostOler1s, on 25 September 2010 - 07:12 PM, said:

You aren't linking to the math and Xlib library. You could figure this out yourself, or you could use allegro-config or pkg-config to do the job. For example, gcc myfile.c -o myprogram `allegro-config --libs`.

Of course, you want to make use of your makefile, so running allegro-config --libs to get the information, and then using that information in your makefile is a smart idea.


IIRC you can add the command itself to the makefile.
Was This Post Helpful? 0
  • +
  • -

#4 yanom  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 70
  • Joined: 05-April 08

Re: Allegro graphics library freaking out on me.

Posted 27 September 2010 - 05:58 PM

OK, thanks
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1