Allegro.cc - Online Community

Allegro.cc Forums » Installation, Setup & Configuration » Error compiling Allegro 5.2 on Ubuntu 16.04

This thread is locked; no one can reply to it. rss feed Print
Error compiling Allegro 5.2 on Ubuntu 16.04
x.Blue
Member #15,768
October 2014

I was working on Allegro 5.0.10 and now I decided to continue my works.
Since I started updating things, Allegro is not working anymore and I can't compile my programs with g++.
First, the compiler was telling me that I need a greater version of allegro (>= 5.0.12) and mine was 5.0.10. The fact is some programs were able to get compiled and working until I started using the native dialog addon.
Second, I updated from github, downloaded the newer version from liballeg.org, downloaded from PPA, but the compiler gives me errors each time anyway.

Errors be like:
(.text+0x20): undefined reference to "main"
(.text+0x20): undefined reference to "al_init"
(.text+0x20): undefined reference to "al_show_native_messagebox"
(.text+0x20): undefined reference to "al_install_..."
etc...
collect2: error: ld returned 1 exit status

What have I done? :-/ Can it be fixed?

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

Undefined references mean you're not linking to enough libraries, or to incorrect ones.

You need to specify the allegro native dialog addon, and the main addon, and anything else you're using when you call pkg-config to get the link options for allegro. I don't use Ubuntu or pkg-config so I can't help you there. Someone else should be along soon.

EDIT
See this link for an example of how to use pkg-config. Replace allegro*-5.0 with 5.2 and it should work.
https://wiki.allegro.cc/index.php?title=Compiling_Allegro_Programs#Allegro_5.x.y

x.Blue
Member #15,768
October 2014

I tried and it's not working.

Package allegro-5.2 was not found in the pkg-config search path.
Perhaps you should add the directory containing `allegro-5.2.pc'
to the PKG_CONFIG_PATH environment variable
No package 'allegro-5.2' found
Package allegro_acodec-5.2 was not found in the pkg-config search path.
Perhaps you should add the directory containing `allegro_acodec-5.2.pc'
to the PKG_CONFIG_PATH environment variable
No package 'allegro_acodec-5.2' found
Package allegro_audio-5.2 was not found in the pkg-config search path.
Perhaps you should add the directory containing `allegro_audio-5.2.pc'
to the PKG_CONFIG_PATH environment variable
No package 'allegro_audio-5.2' found

...the same with all the packages...

g++: fatal error: no input files
compilation terminated.

With "pkg-config --list-all | grep allegro":
allegro_font-5 allegro_font - Allegro game programming library, font addon
allegro_color-5 allegro_color - Allegro game programming library, colors addon
allegro_image-5 allegro_image - Allegro game programming library, image I/O addon
allegro_memfile-5 allegro_memfile - Allegro game programming library, memory files addon
allegro_ttf-5 allegro_ttf - Allegro game programming library, TrueType fonts addon
allegro_physfs-5 allegro_physfs - Allegro game programming library, PhysicsFS addon
allegro_dialog-5 allegro_dialog - Allegro game programming library, native dialog addon
allegro_acodec-5 allegro_acodec - Allegro game programming library, audio codec addon
allegro_video-5 allegro_video - Allegro game programming library, video player addon
allegro_main-5 allegro_main - Allegro game programming library, magic main addon
allegro-5 allegro - Allegro game programming library
allegro_primitives-5 allegro_primitives - Allegro game programming library, primitives addon
allegro_audio-5 allegro_audio - Allegro game programming library, audio addon

I tried with "g++ -o main.cpp `pkg-config --cflags --libs allegro-5 allegro_acodec-5 allegro_audio-5 allegro_color-5 allegro_dialog-5 allegro_font-5 allegro_image-5 allegro_main-5 allegro_memfile-5 allegro_physfs-5 allegro_primitives-5 allegro_ttf-5`" and the output is:
/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/crt1.o: in function "_start":
(.text+0x20): undefined reference to "main"
collect2: error: ld returned 1 exit status

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

x.Blue
Member #15,768
October 2014

The problem was the name of the program after -o (I forgot it)

Now is working!

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

Go to: