Search code examples
cmakefileallegro5

Compiling an allegro5 program using make


I have a program called zone.c that uses the allegro5 library.

I have a makefile that consists of just these two lines.

zone: zone.c
        gcc zone.c -o zone $(pkg-config --cflags --libs allegro-5.0 allegro_primitives-5.0)

when I type "make" I get these errors:

/tmp/ccyCx3Hy.o: In function main': zone.c:(.text+0x14): undefined reference toal_install_system' zone.c:(.text+0x23): undefined reference to al_create_display' zone.c:(.text+0x3b): undefined reference toal_map_rgb' zone.c:(.text+0x70): undefined reference to al_clear_to_color' zone.c:(.text+0x84): undefined reference toal_map_rgb' zone.c:(.text+0xd1): undefined reference to al_draw_filled_circle' zone.c:(.text+0xe5): undefined reference toal_map_rgb' zone.c:(.text+0x132): undefined reference to al_draw_filled_circle' zone.c:(.text+0x137): undefined reference toal_flip_display' zone.c:(.text+0x14f): undefined reference to al_rest' zone.c:(.text+0x15b): undefined reference toal_destroy_display' collect2: error: ld returned 1 exit status make: * [zone] Error 1

But if I just copy out the line "gcc zone.c -o zone $(pkg-config --cflags --libs allegro-5.0 allegro_primitives-5.0)" and run it manually, it compiles fine and the program works.

If I use similar makefiles to compile programmes that don't use allegro5, then make works.

Does anybody have a clue what's going on?


Solution

  • If you want a literal $ in your rule, you have to escape it from make by writing $$ instead:

    zone: zone.c
            gcc zone.c -o zone $$(pkg-config --cflags --libs allegro-5.0 allegro_primitives-5.0)