Allegro 5.2.3 Static Link

I cannot install allegro. A few months ago, I got allegro to statically link on Windows 8.1 using Code::Blocks. But after I updated my installation, my code refused to compile and I got undefined references to everything. So the project I worked on for several months was essentially bricked.

I downloaded the latest Windows binaries, made sure all of the needed libraries and headers were in there, then hooked them up in Code::Blocks. Undefined references. I scrapped Code::Blocks, learned how to write Makefiles, manually set the include/link directories and necessary command line arguments. Undefined references.

I noticed most of the installation instructions were for Linux, and things like pkg-config could handle the command line arguments for you. Out of desperation I wiped my hard drive and did a fresh install of Ubuntu 14.04. With the wiki's guidance, I installed allegro from the Ubuntu PPAs and ran pkg-config in my Makefile. Undefined references.

I checked my installation and there were no actual library files, so I turned to compiling allegro myself. I cloned from git, ran CMake, and it told me I was missing the Thread and OpenGL packages. I installed 4 different pthread packages I saw listed on StackOverflow, still got the CMake errors. I stripped that error-checking and CMake worked. I ran make, it wouldn't recognize sys/cdefs.h. I installed 3-4 different C developer packages, still got the errors. Stripped the errors, was told that allegro was not recognizing the integer width on my platform.

I have no idea what to do at this point. I've gone through dozens of wiki pages, threads, StackOverflow answers and websites to find help every step of the way. There is an overwhelming amount of conflicting information spanning 7 years and several major allegro versions. Most answers still recommend using allegro-config which does not even exist anymore. I'm hopelessly lost and just want to work on my project.

Please give me up-to-date instructions on how to do the installation and static compile of allegro 5.2.3 for 64-bit Ubuntu 14.04. Ubuntu 16.04 is not an option for me because it does not correctly install the firmware for my wireless adapter and therefore I cannot connect to the internet.

Edgar Reynaldo

Directions for Ubuntu are here :

You should also read README.txt, README_cmake.txt, and README_make.txt in the source folder of allegro.

If you're getting undefined references it's either because you haven't linked to the necessary libraries or you're linking to the wrong ones (possible version mismatch).

Instead of restarting from scratch over and over again, why don't you post the instructions you followed and the errors you're getting. It's more than likely we can pinpoint the error(s) right away.


Okay, thank you for directing me to the most up-to-date tutorial. I followed along and the first error I got was when I added the debian repository to my sources.list. When I called apt-get update, I got a lot of errors along the lines of:

W: Failed to fetch 404 Not Found [IP: 2610:148:1f10:3::89 80]

I removed the line and I was able to install all the listed dependencies without any errors. But when I called ccmake, I got:

1WARNING: libwebp not found, disabling support 2WARNING: libopus not found or compile test failed, disabling support. 3WARNING: allegro_video wanted but no supported backend found

I continued anyways and made sure to flag the option PREFER_STATIC_DEPS. Make ran without errors and all of the needed headers and libraries were dumped into /home/platino/allegro5/build/include and /home/platino/allegro5/build/lib respectively. I tried running make on my project but it failed. This was the output:

1platino@platino:~/Documents/C/test$ make 2mkdir -p obj/ 3gcc -o obj/main.o -c src/main.c -std=c11 -pedantic -Wall -Wextra -O3 -Iinclude -I/home/platino/allegro5/build/include -L/home/platino/allegro5/build/lib -lallegro_acodec -lallegro_audio -lallegro_color -lallegro_dialog -lallegro_image -lallegro_main -lallegro_memfile -lallegro_physfs -lallegro_primitives -lallegro_ttf -lallegro_font -lallegro 4src/main.c: In function main: 5src/main.c:4:14: warning: unused parameter argc [-Wunused-parameter] 6 int main(int argc, char **argv){ 7 ^ 8src/main.c:4:27: warning: unused parameter argv [-Wunused-parameter] 9 int main(int argc, char **argv){ 10 ^ 11gcc -o bin/test.exe obj/main.o 12obj/main.o: In function `main': 13main.c:(.text.startup+0xc): undefined reference to `al_install_system' 14main.c:(.text.startup+0x1f): undefined reference to `al_create_display' 15main.c:(.text.startup+0x32): undefined reference to `al_map_rgb' 16main.c:(.text.startup+0x37): undefined reference to `al_clear_to_color' 17main.c:(.text.startup+0x3c): undefined reference to `al_flip_display' 18main.c:(.text.startup+0x49): undefined reference to `al_rest' 19main.c:(.text.startup+0x51): undefined reference to `al_destroy_display' 20collect2: error: ld returned 1 exit status 21make: *** [bin/test.exe] Error 1

The code I'm trying to execute is the example found here. And my makefile:

1CFLAGS := -std=c11 -pedantic -Wall -Wextra -O3 2INCDIR := include /home/platino/allegro5/build/include 3LIBDIR := /home/platino/allegro5/build/lib 4 5INCLUDES := $(foreach d, $(INCDIR), -I$d) 6LIBARIES := $(foreach d, $(LIBDIR), -L$d) -lallegro_acodec -lallegro_audio -lallegro_color -lallegro_dialog -lallegro_image -lallegro_main -lallegro_memfile -lallegro_physfs -lallegro_primitives -lallegro_ttf -lallegro_font -lallegro 7 8SRC := $(wildcard */*.c src/*/*.c) 9OBJ := $(patsubst src/%, %, $(SRC:.c=.o)) 10EXE := bin/test.exe 11 12all: $(EXE) 13 14$(EXE): $(addprefix obj/, $(OBJ)) 15 gcc -o $@ $^ 16 $(EXE) 17 18obj/%.o: $(addprefix src/, %.c) 19 mkdir -p $(dir $@) 20 gcc -o $@ -c $^ $(CFLAGS) $(INCLUDES) $(LIBARIES) 21 22.PHONY: clean 23 24clean: 25 rm -rf ./bin/* 26 rm -rf ./obj/*

I can confirm this makefile works for non-allegro programs. I also tried pkg-config and $(pkg-config) in my LIBRARIES variable but here I just pasted the output of those. Why am I getting undefined references?

Edgar Reynaldo

pkg-config tells you the directories and libraries you need.

If you're going to link statically, then you also need to define ALLEGRO_STATICLINK at the top of every header that uses allegro, or just pass -DALLEGRO_STATICLINK before specifying source files.

To tell pkg-config to link statically, you pass it the --static --libs flags.

I can never remember the names of the allegro libraries, so I always use the monolith - build it by passing -DWANT_MONOLITH=On to CMake.

You can check the output of pkg-config by running it on the command line with grep like so :

pkg-config | grep allegro

Then you'll want to invoke it by passing the correct names of the libraries along with the proper flags, such as --cflags, --libs, and --static before specifying the names of the allegro libraries.

Something else I noticed here :

all: $(EXE)

$(EXE): $(addprefix obj/, $(OBJ)) 
gcc -o $@ $^ 

obj/%.o: $(addprefix src/, %.c) 
mkdir -p $(dir $@) 
gcc -o $@ -c $^ $(CFLAGS) $(INCLUDES) $(LIBARIES)

You're trying to link when creating the .o files. Link when you create the executable, not the object files. So in actuality it's not linking at all, hence your problem.


I see! I knew I might've been missing some of the setup involved to get static linking working. I'll take note of these options and add them to my build setup.

Also, thank you for clearing up the mistake I made in my makefile. I'm still very new to them and that suggestion cleared it up nicely.

Edgar Reynaldo

Bump for reply in case you need anything else...

Thread #617286. Printed from