You are not logged in.

#1 2018-06-23 01:19:56

awesomepilot
Member
Registered: 2012-09-28
Posts: 19

Undefined Reference to EVERYTHING (Allegro5 C game library)

Hello all.  I have decided to get into C, which is quite a jump from Object Oriented JS.  There are lots of wierd concepts that I have to get used to.  I learn programming best when i can see what the code is doing, such as programming some graphics.  Allegro seems to be a popular C game library so I have installed that throught the AUR and worked through one of the examples on the site.  At compile time I get an undefined reference error on all of the functions used.

I know that the install worked because I can find allegro in

/usr/include/allegro5/

, and I get code completions for the functions in there.  I can't get it to work.  I have even tried copying allegro to the project folder and including it via quotes but it won't work.

Clang Error:

/tmp/allegro-0390cf.o: In function `main':
allegro.c:(.text+0x30): undefined reference to `al_install_system'
allegro.c:(.text+0x6d): undefined reference to `al_create_display'
allegro.c:(.text+0xb0): undefined reference to `al_map_rgb'
allegro.c:(.text+0xc7): undefined reference to `al_clear_to_color'
allegro.c:(.text+0xcc): undefined reference to `al_flip_display'
allegro.c:(.text+0xd9): undefined reference to `al_rest'
allegro.c:(.text+0xe2): undefined reference to `al_destroy_display'
clang-6.0: error: linker command failed with exit code 1 (use -v to see
 invocation)

GCC Error:

/tmp/cc1UQ5BG.o: In function `main':
allegro.c:(.text+0x28): undefined reference to `al_install_system'
allegro.c:(.text+0x68): undefined reference to `al_create_display'
allegro.c:(.text+0xae): undefined reference to `al_map_rgb'
allegro.c:(.text+0xdb): undefined reference to `al_clear_to_color'
allegro.c:(.text+0xe0): undefined reference to `al_flip_display'
allegro.c:(.text+0xed): undefined reference to `al_rest'
allegro.c:(.text+0xf9): undefined reference to `al_destroy_display'
collect2: error: ld returned 1 exit status

Code:

#include <stdio.h>
#include <stdlib.h>
//#include <allegro5/allegro.h>
#include "allegro5/allegro.h"    //My attempt to see if I could get it to work directly from the project folder.
#include "allegro5/display.h"

int main(int argc, char **argv){
  ALLEGRO_DISPLAY *display = NULL;
  if(!al_init()){
    fprintf(stderr, "Failed to initialize allegro!\n");
    return -1;
  }

  display = al_create_display(500, 500);
  if(!display){
    fprintf(stderr, "Failed to create display!\n");
    return -1;
  }

  al_clear_to_color(al_map_rgb(0, 0, 0));
  al_flip_display();
  al_rest(10.0);
  al_destroy_display(display);
  return 0;
}

I have seen many other problems like this but in most of those, they didn't have the lib installed correctly and could not find it in their includes directory.  I am using the clang compiler, as well as gcc.  Both produce the same error so its something im not getting.  Any veteran C programmers out there?  If so please lend me some insight.  I have not been able to figure this out in a couple days.  I bet its something simple and stupid that I'm missing.

Offline

#2 2018-06-23 07:44:30

ayekat
Member
Registered: 2011-01-17
Posts: 1,589

Re: Undefined Reference to EVERYTHING (Allegro5 C game library)

Most importantly: What is the (full) command you use to compile?

The error is from the linker, so it's not a problem with the include directories (if you got this far, they're probably fine). My guess is that you are missing library flags for the linking step.

Check if the allegro package provides a .pc file in /usr/share/pkgconfig. In that case, you can use pkg-config to find out which flags you need to pass to the compiler. Here is an example of pkg-config usage for yajl:

$ pkg-config --cflags yajl
-I/usr/include/yajl
$ pkg-config --libs yajl
-lyajl              ← probably missing this one

Last edited by ayekat (2018-06-23 07:48:12)


pkgshackscfgblag

Offline

Board footer

Powered by FluxBB