Allegro.cc - Online Community

Allegro.cc Forums » Installation, Setup & Configuration » Static Libraries - reference undefined only for addons

This thread is locked; no one can reply to it. rss feed Print
Static Libraries - reference undefined only for addons
huguesdpdn
Member #16,616
January 2017

Hi !

I would like to compile my program on an UNIX distrib in static mode.
So I start to make a basic program, initializing and destroying all addons and displaying a single picture.

But the compilation doesn't work when I try to use the addons functions.

Did I miss something ??? ?

Here is some information that may help you:

$> make
gcc -W -Wextra -Wall -Werror -Wfatal-errors -IINCLUDES -c -o SOURCES/main.o SOURCES/main.c
gcc -W -Wextra -Wall -Werror -Wfatal-errors -IINCLUDES -c -o SOURCES/HUD_number.o SOURCES/HUD_number.c
gcc -W -Wextra -Wall -Werror -Wfatal-errors -IINCLUDES -c -o SOURCES/HUD_text.o SOURCES/HUD_text.c
gcc -W -Wextra -Wall -Werror -Wfatal-errors -IINCLUDES -c -o SOURCES/HUD_graphics_init_shutdown.o SOURCES/HUD_graphics_init_shutdown.c
gcc -W -Wextra -Wall -Werror -Wfatal-errors -IINCLUDES -c -o SOURCES/get_random.o SOURCES/get_random.c
gcc -o hud -W -Wextra -Wall -Werror -Wfatal-errors -IINCLUDES SOURCES/main.o
SOURCES/main.o: In function `main':
main.c:(.text+0x22): undefined reference to `al_install_system'
main.c:(.text+0x31): undefined reference to `al_create_display'
main.c:(.text+0x9c): undefined reference to `al_flip_display'
main.c:(.text+0xbe): undefined reference to `al_destroy_display'
SOURCES/HUD_graphics_init_shutdown.o: In function `graphics_init':
HUD_graphics_init_shutdown.c:(.text+0x5): undefined reference to `al_install_audio'
HUD_graphics_init_shutdown.c:(.text+0x18): undefined reference to `al_init_acodec_addon'
HUD_graphics_init_shutdown.c:(.text+0x2b): undefined reference to `al_init_font_addon'
HUD_graphics_init_shutdown.c:(.text+0x3e): undefined reference to `al_init_image_addon'
HUD_graphics_init_shutdown.c:(.text+0x51): undefined reference to `al_init_primitives_addon'
HUD_graphics_init_shutdown.c:(.text+0x64): undefined reference to `al_init_video_addon'
HUD_graphics_init_shutdown.c:(.text+0x77): undefined reference to `al_set_physfs_file_interface'
HUD_graphics_init_shutdown.c:(.text+0x7c): undefined reference to `al_get_allegro_physfs_version'
SOURCES/HUD_graphics_init_shutdown.o: In function `graphics_shutdown':
HUD_graphics_init_shutdown.c:(.text+0x9d): undefined reference to `al_uninstall_audio'
HUD_graphics_init_shutdown.c:(.text+0xa2): undefined reference to `al_shutdown_font_addon'
HUD_graphics_init_shutdown.c:(.text+0xa7): undefined reference to `al_shutdown_image_addon'
HUD_graphics_init_shutdown.c:(.text+0xac): undefined reference to `al_shutdown_primitives_addon'
HUD_graphics_init_shutdown.c:(.text+0xb1): undefined reference to `al_shutdown_video_addon'
collect2: error: ld returned 1 exit status
Makefile:26: recipe for target 'hud' failed
make: *** [hud] Error 1

$> tree
├── FONTS
│   └── HUD.ttf
├── IMAGES
│   ├── HUD_Numbers.png
│   ├── HUD_Range_Horizontal.png
│   ├── HUD_Range_Vertical.png
├── INCLUDES
│   ├── HUD.h
│   ├── HUD_includes_graphics.h
│   ├── HUD_includes_system.h
│   ├── HUD_prototypes.h
│   └── HUD_types.h
├── LICENSE_Allegro.txt
├── Makefile
└── SOURCES
├── get_random.c
├── HUD_graphics_init_shutdown.c
├── HUD_number.c
├── HUD_text.c
└── main.c

$> cat Makefile
NAME = hud

COMPILER = gcc

INCLUDES_DIR += -IINCLUDES
SOURCES_DIR += SOURCES

COMPILER_FLAGS += -W -Wextra -Wall -Werror -Wfatal-errors
COMPILER_FLAGS += $(INCLUDES_DIR)

SOURCES_FILES += main.c
SOURCES_FILES += HUD_number.c
SOURCES_FILES += HUD_text.c
SOURCES_FILES += HUD_graphics_init_shutdown.c
SOURCES_FILES += get_random.c #### Just for test, do not forget to remove it ####

CC = $(COMPILER)
CFLAGS = $(COMPILER_FLAGS)
SRCS = $(addprefix $(SOURCES_DIR)/, $(SOURCES_FILES))
OBJS = $(SRCS:.c=.o)
RM = rm -f

all: $(NAME)

$(NAME): $(OBJS)
$(CC) -o $(NAME) $(CFLAGS) $(OBJS) -L/usr/local/lib $(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_memfile-5 allegro_physfs-5 allegro_primitives-5 allegro_ttf-5 allegro_main-5)

clean:
$(RM) $(OBJS)

fclean: clean
$(RM) $(NAME)

re: fclean all

.PHONY: all clean fclean re

Here is how I compiled allegro-5.2.2 :
$> cmake -DSHARED=0 -DWANT_STATIC_RUNTIME=on allegro-5.2.2.0/
$> make
$> sudo make install
$> sudo ldconfig

All files about allegro:
/usr/include/allegro5
/usr/include/allegro5/alcompat.h
/usr/include/allegro5/alinline.h
/usr/include/allegro5/allegro.h
/usr/include/allegro5/allegro5.h
/usr/include/allegro5/allegro_direct3d.h
/usr/include/allegro5/allegro_image.h
/usr/include/allegro5/allegro_opengl.h
/usr/include/allegro5/altime.h
/usr/include/allegro5/base.h
/usr/include/allegro5/bitmap.h
/usr/include/allegro5/bitmap_draw.h
/usr/include/allegro5/bitmap_io.h
/usr/include/allegro5/bitmap_lock.h
/usr/include/allegro5/blender.h
/usr/include/allegro5/color.h
/usr/include/allegro5/config.h
/usr/include/allegro5/debug.h
/usr/include/allegro5/display.h
/usr/include/allegro5/drawing.h
/usr/include/allegro5/error.h
/usr/include/allegro5/events.h
/usr/include/allegro5/file.h
/usr/include/allegro5/fixed.h
/usr/include/allegro5/fmaths.h
/usr/include/allegro5/fshook.h
/usr/include/allegro5/fullscreen_mode.h
/usr/include/allegro5/inline
/usr/include/allegro5/internal
/usr/include/allegro5/joystick.h
/usr/include/allegro5/keyboard.h
/usr/include/allegro5/keycodes.h
/usr/include/allegro5/memory.h
/usr/include/allegro5/monitor.h
/usr/include/allegro5/mouse.h
/usr/include/allegro5/mouse_cursor.h
/usr/include/allegro5/opengl
/usr/include/allegro5/path.h
/usr/include/allegro5/platform
/usr/include/allegro5/system.h
/usr/include/allegro5/threads.h
/usr/include/allegro5/timer.h
/usr/include/allegro5/tls.h
/usr/include/allegro5/transformations.h
/usr/include/allegro5/utf8.h
/usr/include/allegro5/inline/fmaths.inl
/usr/include/allegro5/internal/alconfig.h
/usr/include/allegro5/opengl/GLext
/usr/include/allegro5/opengl/gl_ext.h
/usr/include/allegro5/opengl/GLext/gl_ext_alias.h
/usr/include/allegro5/opengl/GLext/gl_ext_api.h
/usr/include/allegro5/opengl/GLext/gl_ext_defs.h
/usr/include/allegro5/opengl/GLext/gl_ext_list.h
/usr/include/allegro5/opengl/GLext/glx_ext_alias.h
/usr/include/allegro5/opengl/GLext/glx_ext_api.h
/usr/include/allegro5/opengl/GLext/glx_ext_defs.h
/usr/include/allegro5/opengl/GLext/glx_ext_list.h
/usr/include/allegro5/opengl/GLext/wgl_ext_alias.h
/usr/include/allegro5/opengl/GLext/wgl_ext_api.h
/usr/include/allegro5/opengl/GLext/wgl_ext_defs.h
/usr/include/allegro5/opengl/GLext/wgl_ext_list.h
/usr/include/allegro5/platform/albcc32.h
/usr/include/allegro5/platform/aliphone.h
/usr/include/allegro5/platform/aliphonecfg.h
/usr/include/allegro5/platform/almngw32.h
/usr/include/allegro5/platform/almsvc.h
/usr/include/allegro5/platform/alosx.h
/usr/include/allegro5/platform/alosxcfg.h
/usr/include/allegro5/platform/alplatf.h
/usr/include/allegro5/platform/alucfg.h
/usr/include/allegro5/platform/alunix.h
/usr/include/allegro5/platform/alwatcom.h
/usr/include/allegro5/platform/alwin.h
/usr/include/allegro5/platform/astdbool.h
/usr/include/allegro5/platform/astdint.h
/usr/lib64/allegro
/usr/lib64/liballegro.so
/usr/lib64/liballegro.so.5.0
/usr/lib64/liballegro.so.5.0.10
/usr/lib64/liballegro_image.so
/usr/lib64/liballegro_image.so.5.0
/usr/lib64/liballegro_image.so.5.0.10
/usr/lib64/allegro/4.4.2
/usr/lib64/allegro/4.4.2/alleg-alsadigi.so
/usr/lib64/allegro/4.4.2/alleg-alsamidi.so
/usr/lib64/allegro/4.4.2/alleg-dga2.so
/usr/lib64/allegro/4.4.2/alleg-jack.so
/usr/lib64/allegro/4.4.2/modules.lst
/usr/lib64/firefox/browser/extensions/langpack-pl@firefox.mozilla.org/browser/chrome/pl/locale/browser/searchplugins/allegro-pl.xml
/usr/lib64/pkgconfig/allegro-5.0.pc
/usr/lib64/pkgconfig/allegro-5.pc
/usr/lib64/pkgconfig/allegro_image-5.0.pc
/usr/lib64/pkgconfig/allegro_image-5.pc
/usr/lib64/thunderbird/extensions/langpack-pl@thunderbird.mozilla.org/chrome/pl/locale/pl/messenger/searchplugins/allegro-pl.xml
/usr/share/doc/packages/liballegro5_0
/usr/share/doc/packages/liballegro5_0/CHANGES-5.0.txt
/usr/share/doc/packages/liballegro5_0/CONTRIBUTORS.txt
/usr/share/doc/packages/liballegro5_0/LICENSE.txt
/usr/share/susehelp/meta/Development/Libraries/allegro-devel.desktop

And some additional version information:

  • OS: OpenSUsE Leap 42.1 (64bits)

  • gcc: 4.8.5

  • make: 4.0

  • cmake: 3.3.2

  • pkg-config: 0.28

I am sure I am wrong, but where :'( ?

EDIT:

Happy new Year !! :D

GullRaDriel
Member #3,861
September 2003
avatar

That may be taken out of the CC cmd and resolved one time for all

$(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_memfile-5 allegro_physfs-5 allegro_primitives-5 allegro_ttf-5 allegro_main-5)

Like that:

LIBS=$(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_memfile-5 allegro_physfs-5 allegro_primitives-5 allegro_ttf-5 allegro_main-5)

$(CC) -o $(NAME) $(CFLAGS) $(OBJS) $(LIBS)

I edited: parenthesis around LIBS, and I don't think that specifying system lib path is needed so no -I

"Code is like shit - it only smells if it is not yours"
Allegro Wiki, full of examples and articles !!

huguesdpdn
Member #16,616
January 2017

Hi GullRaDriel,

thank for your quick reply.

I also try your solution, but unfortunately it seems doesn't work :-/

First, notice that I remove "allegro_dialog-5", seems it's not available for my operating system.

I set a LIB var as requested in my Makefile, but nothing.
You seems right, I try the command directly in my shell, and the output give me:
-I/usr/local/include

Inside this directory, I have a allegro5 directory containing:
ls usr/local/include/allegro5
alcompat.h allegro_primitives.h color.h fullscreen_mode.h path.h
allegro5.h allegro_ttf.h config.h haptic.h platform
allegro_acodec.h allegro_video.h cpu.h inline render_state.h
allegro_audio.h allegro_x.h debug.h internal shader.h
allegro_color.h altime.h display.h joystick.h system.h
allegro_direct3d.h base.h drawing.h keyboard.h threads.h
allegro_font.h bitmap_draw.h error.h keycodes.h timer.h
allegro.h bitmap.h events.h memory.h tls.h
allegro_image.h bitmap_io.h file.h monitor.h touch_input.h
allegro_memfile.h bitmap_lock.h fixed.h mouse_cursor.h transformations.h
allegro_opengl.h blender.h fmaths.h mouse.h utf8.h
allegro_physfs.h clipboard.h fshook.h opengl

Unfortunately, always the same output as above when compiling.
Seems all about headers is okay, it's the linking that is the problem.

Any idea ?

GullRaDriel
Member #3,861
September 2003
avatar

Try that way:
$(CC) $(CFLAGS) $(OBJS) -o $(NAME) $(LIBS)

If at that line in the make output:
gcc -o hud -W -Wextra -Wall -Werror -Wfatal-errors -IINCLUDES SOURCES/main.o
There still isn't any -lallegro_module displayed, you're using the wrong variable or pkgconfig is broken.

EDIT: that was already the problem since the line I took is from your first post.

"Code is like shit - it only smells if it is not yours"
Allegro Wiki, full of examples and articles !!

huguesdpdn
Member #16,616
January 2017

Ok, I found why (maybe also because I am a bit stupid ;D). I used ADDONS, this means that when I compiled allegro, some flags were missing.

So, If you want to use allegro with all addons, you must correctly configure cmake.

First:
Download allegro and go to the parent directory.

Second:
Configure allegro with cmake with this command line:
DYNAMIC :
cmake -DWANT_STATIC_RUNTIME=on -DWANT_OPENGL=1 -DWANT_FONT=1 -DWANT_AUDIO=1 -DWANT_IMAGE=1 -DWANT_IMAGE_JPG=1 -DWANT_IMAGE_PNG=1 -DWANT_TTF=1 -DWANT_COLOR=1 -DWANT_MEMFILE=1 -DWANT_PHYSFS=1 -DWANT_PRIMITIVES=1 -DWANT_NATIVE_DIALOG=1 -DWANT_VIDEO=1 -DWANT_MONOLITH=1 -DWANT_X11=1 -DWANT_FLAC=1 -DWANT_ACODEC_DYNAMIC_LOAD=1 -DWANT_VORBIS=1 -DWANT_TREMOR=1 -DWANT_OPUS=1 -DWANT_MODAUDIO=1 -DWANT_OPENAL=1 allegro-5.2.2.0/
STATIC :
cmake -DWANT_STATIC_RUNTIME=on -DWANT_OPENGL=1 -DWANT_FONT=1 -DWANT_AUDIO=1 -DWANT_IMAGE=1 -DWANT_IMAGE_JPG=1 -DWANT_IMAGE_PNG=1 -DWANT_TTF=1 -DWANT_COLOR=1 -DWANT_MEMFILE=1 -DWANT_PHYSFS=1 -DWANT_PRIMITIVES=1 -DWANT_NATIVE_DIALOG=1 -DWANT_VIDEO=1 -DWANT_MONOLITH=1 -DWANT_X11=1 -DWANT_FLAC=1 -DWANT_ACODEC_DYNAMIC_LOAD=1 -DWANT_VORBIS=1 -DWANT_TREMOR=1 -DWANT_OPUS=1 -DWANT_MODAUDIO=1 -DWANT_OPENAL=1 -DSHARED=0 allegro-5.2.2.0/
Note : I think some flags are useless or deprecated, but I don't know which one so I set them all ;D

Third:
Compile and install:
$> make
$> sudo make install
$> sudo ldconfig

Third (bis):
Note: Only for static use, ONLY.
Copy the lib/pkgconfig/allegro_*-static-5.pc into same directory of your Makefile, like:
cp ~/Downloads/allegro-5.2.2/lib/pkgconfig/* my/project/directory
OR
Set the path for pkg-config, var name is PKG_CONFIG_PATH.
You can add this line into your .bashrc or /etc/environment file:
export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig
Note: I don't know how to set it directly into the Makefile :-[

Four:
Create your Makefile, the output must be something like this:
DYNAMIC :
gcc -W -Wextra -Wall -Werror -Iincludes srcs/main.c srcs/file_name1.c srcs/file_name3.c srcs/file_name3.c -lallegro_monolith
STATIC :
gcc -W -Wextra -Wall -Werror -Iincludes srcs/main.c srcs/file_name1.c srcs/file_name3.c srcs/file_name3.c -I/usr/local/include -L/usr/local/lib -lallegro_monolith-static -lm -lpthread -lSM -lICE -lX11 -lXext -lXcursor -lXi -lXinerama -lXrandr -lGLU -lGL -lpng -lz -ljpeg -lpulse-simple -lpulse -lasound -lopenal -lFLAC -logg -lopusfile -lopus -logg -lfreetype -lz -lphysfs -ltheoradec -logg -lvorbisfile -lvorbis -logg
So here is mine as example:
PROGRAM_NAME = my_program_name

COMPILER = gcc

INCLUDES_DIR += includes
SOURCES_DIR += srcs

COMPILER_FLAGS += -W
COMPILER_FLAGS += -Wall
COMPILER_FLAGS += $(addprefix -I, $(INCLUDES_DIR))

SOURCES_FILES += file_name1.c
SOURCES_FILES += file_name2.c
SOURCES_FILES += file_name3.c

NAME = $(PROGRAM_NAME)
CC = $(COMPILER)
CFLAGS = $(COMPILER_FLAGS)
SRCS = $(addprefix $(SOURCES_DIR)/, $(SOURCES_FILES))
OBJS = $(SRCS:.c=.o)
DYNAMIC :
LIBS = -lallegro_monolith
STATIC :
LIBS = `pkg-config --cflags --static --libs allegro_monolith-static-5.pc`
RM = rm -f

all: $(NAME)

$(NAME): $(OBJS)
$(CC) $(CFLAGS) $(SRCS) $(LIBS) -o $(NAME)

clean:
$(RM) $(OBJS)

fclean: clean
$(RM) $(NAME)

re: fclean all

.PHONY: all clean fclean re

Five:
Enjoy :D

So why it's was not working before ?
It's depend from which program you compile it.
Shell : $(pkg-config ...)
Makefile: `pkg-config ...`
Note: for Makefile version, use the reverse accent on key "7" for European keyboards. For US keyboards, it's the key under the Echap Key.

Go to: