Allegro.cc - Online Community

Allegro.cc Forums » Installation, Setup & Configuration » Having troouble with syatic linking on MSYS2

Credits go to AceBlkwell, Edgar Reynaldo, and GullRaDriel for helping out!
This thread is locked; no one can reply to it. rss feed Print
Having troouble with syatic linking on MSYS2
iheartcoffee
Member #16,518
August 2016
avatar

I've been trying to statically link Allegro but I keep getting an error and I can't seem to figure out what it is:

#SelectExpand
1g++ -o allegro.exe allegro.o -static -lallegro_monolith-static -ljpeg -ldumb -lFLAC -lfreetype -lvorbisfile -lvorbis -logg -lphysfs -lpng16 -lz -ldsound -lgdiplus -luuid -lkernel32 -lwinmm -lpsapi -lopengl32 -lglu32 -luser32 -lcomdlg32 -lgdi32 -lshell32 -lole32 -ladvapi32 -lws2_32 -lshlwapi -static-libstdc++ -static-libgcc -Wl,--subsystem,windows >> text.txt 2C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/9.1.0/../../../../lib\libfreetype.a(autofit.o): In function `af_face_globals_free': 3C:/msys64/home/jador/freetype-2.10.1/src/autofit/afglobal.c:408: undefined reference to `hb_font_destroy' 4C:/msys64/home/jador/freetype-2.10.1/src/autofit/afglobal.c:409: undefined reference to `hb_buffer_destroy' 5C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/9.1.0/../../../../lib\libfreetype.a(autofit.o): In function `af_shaper_get_coverage': 6C:/msys64/home/jador/freetype-2.10.1/src/autofit/afshaper.c:128: undefined reference to `hb_font_get_face' 7C:/msys64/home/jador/freetype-2.10.1/src/autofit/afshaper.c:136: undefined reference to `hb_ot_tags_from_script' 8C:/msys64/home/jador/freetype-2.10.1/src/autofit/afshaper.c:166: undefined reference to `hb_set_create' 9C:/msys64/home/jador/freetype-2.10.1/src/autofit/afshaper.c:167: undefined reference to `hb_ot_layout_collect_lookups' 10C:/msys64/home/jador/freetype-2.10.1/src/autofit/afshaper.c:174: undefined reference to `hb_set_is_empty' 11C:/msys64/home/jador/freetype-2.10.1/src/autofit/afshaper.c:185: undefined reference to `hb_set_create' 12C:/msys64/home/jador/freetype-2.10.1/src/autofit/afshaper.c:194: undefined reference to `hb_ot_layout_lookup_collect_glyphs' 13C:/msys64/home/jador/freetype-2.10.1/src/autofit/afshaper.c:186: undefined reference to `hb_set_next' 14C:/msys64/home/jador/freetype-2.10.1/src/autofit/afshaper.c:213: undefined reference to `hb_set_create' 15C:/msys64/home/jador/freetype-2.10.1/src/autofit/afshaper.c:214: undefined reference to `hb_ot_layout_collect_lookups' 16C:/msys64/home/jador/freetype-2.10.1/src/autofit/afshaper.c:225: undefined reference to `hb_set_create' 17C:/msys64/home/jador/freetype-2.10.1/src/autofit/afshaper.c:234: undefined reference to `hb_ot_layout_lookup_collect_glyphs' 18C:/msys64/home/jador/freetype-2.10.1/src/autofit/afshaper.c:226: undefined reference to `hb_set_next' 19C:/msys64/home/jador/freetype-2.10.1/src/autofit/afshaper.c:281: undefined reference to `hb_ot_layout_lookup_would_substitute' 20C:/msys64/home/jador/freetype-2.10.1/src/autofit/afshaper.c:275: undefined reference to `hb_set_next' 21C:/msys64/home/jador/freetype-2.10.1/src/autofit/afshaper.c:346: undefined reference to `hb_set_subtract' 22C:/msys64/home/jador/freetype-2.10.1/src/autofit/afshaper.c:353: undefined reference to `hb_set_next' 23C:/msys64/home/jador/freetype-2.10.1/src/autofit/afshaper.c:353: undefined reference to `hb_set_next' 24C:/msys64/home/jador/freetype-2.10.1/src/autofit/afshaper.c:386: undefined reference to `hb_set_destroy' 25C:/msys64/home/jador/freetype-2.10.1/src/autofit/afshaper.c:387: undefined reference to `hb_set_destroy' 26C:/msys64/home/jador/freetype-2.10.1/src/autofit/afshaper.c:388: undefined reference to `hb_set_destroy' 27C:/msys64/home/jador/freetype-2.10.1/src/autofit/afshaper.c:389: undefined reference to `hb_set_destroy' 28C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/9.1.0/../../../../lib\libfreetype.a(autofit.o): In function `af_face_globals_new': 29C:/msys64/home/jador/freetype-2.10.1/src/autofit/afglobal.c:362: undefined reference to `hb_ft_font_create' 30C:/msys64/home/jador/freetype-2.10.1/src/autofit/afglobal.c:363: undefined reference to `hb_buffer_create' 31C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/9.1.0/../../../../lib\libfreetype.a(autofit.o): In function `af_shaper_get_cluster': 32C:/msys64/home/jador/freetype-2.10.1/src/autofit/afshaper.c:469: undefined reference to `hb_font_set_scale' 33C:/msys64/home/jador/freetype-2.10.1/src/autofit/afshaper.c:481: undefined reference to `hb_buffer_clear_contents' 34C:/msys64/home/jador/freetype-2.10.1/src/autofit/afshaper.c:482: undefined reference to `hb_buffer_add_utf8' 35C:/msys64/home/jador/freetype-2.10.1/src/autofit/afshaper.c:485: undefined reference to `hb_buffer_guess_segment_properties' 36C:/msys64/home/jador/freetype-2.10.1/src/autofit/afshaper.c:489: undefined reference to `hb_shape' 37C:/msys64/home/jador/freetype-2.10.1/src/autofit/afshaper.c:506: undefined reference to `hb_buffer_clear_contents' 38C:/msys64/home/jador/freetype-2.10.1/src/autofit/afshaper.c:507: undefined reference to `hb_buffer_add_utf8' 39C:/msys64/home/jador/freetype-2.10.1/src/autofit/afshaper.c:508: undefined reference to `hb_buffer_guess_segment_properties' 40C:/msys64/home/jador/freetype-2.10.1/src/autofit/afshaper.c:509: undefined reference to `hb_shape' 41C:/msys64/home/jador/freetype-2.10.1/src/autofit/afshaper.c:511: undefined reference to `hb_buffer_get_glyph_infos' 42C:/msys64/home/jador/freetype-2.10.1/src/autofit/afshaper.c:512: undefined reference to `hb_buffer_get_glyph_infos' 43C:/msys64/home/jador/freetype-2.10.1/src/autofit/afshaper.c:531: undefined reference to `hb_buffer_get_length' 44C:/msys64/home/jador/freetype-2.10.1/src/autofit/afshaper.c:526: undefined reference to `hb_buffer_clear_contents' 45C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/9.1.0/../../../../lib\libfreetype.a(autofit.o): In function `af_shaper_get_elem': 46C:/msys64/home/jador/freetype-2.10.1/src/autofit/afshaper.c:558: undefined reference to `hb_buffer_get_glyph_infos' 47C:/msys64/home/jador/freetype-2.10.1/src/autofit/afshaper.c:559: undefined reference to `hb_buffer_get_glyph_positions' 48C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/9.1.0/../../../../lib\libfreetype.a(autofit.o): In function `af_shaper_buf_create': 49C:/msys64/home/jador/freetype-2.10.1/src/autofit/afshaper.c:431: undefined reference to `hb_buffer_create' 50C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/9.1.0/../../../../lib\libfreetype.a(autofit.o): In function `af_shaper_buf_destroy': 51C:/msys64/home/jador/freetype-2.10.1/src/autofit/afshaper.c:441: undefined reference to `hb_buffer_destroy' 52C:/msys64/home/jador/freetype-2.10.1/src/autofit/afshaper.c:441: undefined reference to `hb_buffer_destroy' 53C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/9.1.0/../../../../lib\libfreetype.a(autofit.o): In function `af_shaper_buf_create': 54C:/msys64/home/jador/freetype-2.10.1/src/autofit/afshaper.c:431: undefined reference to `hb_buffer_create' 55C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/9.1.0/../../../../lib\libfreetype.a(autofit.o): In function `af_shaper_buf_destroy': 56C:/msys64/home/jador/freetype-2.10.1/src/autofit/afshaper.c:441: undefined reference to `hb_buffer_destroy' 57C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/9.1.0/../../../../lib\libfreetype.a(autofit.o): In function `af_shaper_buf_create': 58C:/msys64/home/jador/freetype-2.10.1/src/autofit/afshaper.c:431: undefined reference to `hb_buffer_create' 59C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/9.1.0/../../../../lib\libfreetype.a(autofit.o): In function `af_shaper_buf_destroy': 60C:/msys64/home/jador/freetype-2.10.1/src/autofit/afshaper.c:441: undefined reference to `hb_buffer_destroy' 61C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/9.1.0/../../../../lib\libfreetype.a(autofit.o): In function `af_shaper_buf_create': 62C:/msys64/home/jador/freetype-2.10.1/src/autofit/afshaper.c:431: undefined reference to `hb_buffer_create' 63C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/9.1.0/../../../../lib\libfreetype.a(autofit.o): In function `af_shaper_buf_destroy': 64C:/msys64/home/jador/freetype-2.10.1/src/autofit/afshaper.c:441: undefined reference to `hb_buffer_destroy' 65C:/msys64/home/jador/freetype-2.10.1/src/autofit/afshaper.c:441: undefined reference to `hb_buffer_destroy' 66C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/9.1.0/../../../../lib\libfreetype.a(autofit.o): In function `af_shaper_buf_create': 67C:/msys64/home/jador/freetype-2.10.1/src/autofit/afshaper.c:431: undefined reference to `hb_buffer_create' 68C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/9.1.0/../../../../lib\libfreetype.a(autofit.o): In function `af_shaper_buf_destroy': 69C:/msys64/home/jador/freetype-2.10.1/src/autofit/afshaper.c:441: undefined reference to `hb_buffer_destroy' 70C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/9.1.0/../../../../lib\libfreetype.a(autofit.o): In function `af_shaper_buf_create': 71C:/msys64/home/jador/freetype-2.10.1/src/autofit/afshaper.c:431: undefined reference to `hb_buffer_create' 72C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/9.1.0/../../../../lib\libfreetype.a(autofit.o): In function `af_shaper_buf_destroy': 73C:/msys64/home/jador/freetype-2.10.1/src/autofit/afshaper.c:441: undefined reference to `hb_buffer_destroy' 74C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/9.1.0/../../../../lib\libfreetype.a(autofit.o): In function `af_shaper_buf_create': 75C:/msys64/home/jador/freetype-2.10.1/src/autofit/afshaper.c:431: undefined reference to `hb_buffer_create' 76C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/9.1.0/../../../../lib\libfreetype.a(autofit.o): In function `af_shaper_buf_destroy': 77C:/msys64/home/jador/freetype-2.10.1/src/autofit/afshaper.c:441: undefined reference to `hb_buffer_destroy' 78C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/9.1.0/../../../../lib\libfreetype.a(ftbzip2.o): In function `ft_bzip2_file_done': 79C:/msys64/home/jador/freetype-2.10.1/src/bzip2/ftbzip2.c:193: undefined reference to `BZ2_bzDecompressEnd' 80C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/9.1.0/../../../../lib\libfreetype.a(ftbzip2.o): In function `ft_bzip2_file_fill_output': 81C:/msys64/home/jador/freetype-2.10.1/src/bzip2/ftbzip2.c:304: undefined reference to `BZ2_bzDecompress' 82C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/9.1.0/../../../../lib\libfreetype.a(ftbzip2.o): In function `ft_bzip2_file_reset': 83C:/msys64/home/jador/freetype-2.10.1/src/bzip2/ftbzip2.c:222: undefined reference to `BZ2_bzDecompressEnd' 84C:/msys64/home/jador/freetype-2.10.1/src/bzip2/ftbzip2.c:233: undefined reference to `BZ2_bzDecompressInit' 85C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/9.1.0/../../../../lib\libfreetype.a(ftbzip2.o): In function `ft_bzip2_file_init': 86C:/msys64/home/jador/freetype-2.10.1/src/bzip2/ftbzip2.c:178: undefined reference to `BZ2_bzDecompressInit' 87collect2.exe: error: ld returned 1 exit status

I don't know what I should do. When I remove the -static option it links. Help :)

GullRaDriel
Member #3,861
September 2003
avatar

Try with this:

-Wl,-Bstatic mystaticlibs here -Wl,-Bdynamic mydynlibs here

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

iheartcoffee
Member #16,518
August 2016
avatar

I want to statically link all the libraries so that I don't have to distribute the DLL files.

I followed this to build the Allegro library. I also set the cmake option -SHARED=Off when building the library. What should I do?

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

AceBlkwell
Member #13,038
July 2011
avatar

Coffee,

I’m far from an expert here, but with MUCH coaching by Edgar I was able to get my program to statically link in Windows. I wasn’t so lucky in Linux. In any case, I can’t swear this will work but it did when I tried it using DevC++ portable. I used the Project Options to add these so I’m not 100% sure how to add at the command line . Oh and I am using Allegro 4 not 5. Not sure if that makes a difference or not either.

Linker parameters
-static
-lalleggl
-ljpgalleg
-lloadpng
-llogg
-lalleg-debug-static
-lvorbis
-lvorbisenc
-lvorbisfile
-logg
-lpng16
-lzlibstatic
-lkernel32
-luser32
-lgdi32
-lcomdlg32
-lole32
-ldinput
-lddraw
-ldxguid
-lwinmm
-ldsound

C++compiler parameter
-static-libstdc++
-static-libgcc

Also you need to add #define ALLEGRO_STATICLINK to the include section of each cpp file used.

Edgar correct me where I’m wrong.

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

iheartcoffee
Member #16,518
August 2016
avatar

I rebuilt Harfbuzz, Freetype and BZip2 libraries... but now I'm getting the following error:

g++ -o allegro.exe allegro.o -static -lallegro_monolith-static -ljpeg -ldumb -lFLAC -ltheora -lvorbisfile -lvorbis -logg -lphysfs -lfreetype -lharfbuzz -lpng16 -lz -ldsound -lgdiplus -luuid -lkernel32 -lwinmm -lpsapi -lopengl32 -lglu32 -luser32 -lcomdlg32 -lgdi32 -lshell32 -lole32 -ladvapi32 -lws2_32 -lshlwapi -lpthread -static-libstdc++ -static-libgcc -Wl,--subsystem,windows
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/9.1.0/../../../../lib\libfreetype.a(ftbzip2.c.obj):ftbzip2.c:(.text+0x217): undefined reference to `BZ2_bzDecompressInit'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/9.1.0/../../../../lib\libfreetype.a(ftbzip2.c.obj):ftbzip2.c:(.text+0x264): undefined reference to `BZ2_bzDecompressEnd'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/9.1.0/../../../../lib\libfreetype.a(ftbzip2.c.obj):ftbzip2.c:(.text+0x32c): undefined reference to `BZ2_bzDecompressEnd'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/9.1.0/../../../../lib\libfreetype.a(ftbzip2.c.obj):ftbzip2.c:(.text+0x3bb): undefined reference to `BZ2_bzDecompressInit'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/9.1.0/../../../../lib\libfreetype.a(ftbzip2.c.obj):ftbzip2.c:(.text+0x578): undefined reference to `BZ2_bzDecompress'
collect2.exe: error: ld returned 1 exit status

I rebuilt Allegro several times. I'm not sure what to do now.

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

AceBlkwell
Member #13,038
July 2011
avatar

Coffee, last time I had a similar error I was trying to compile a small program using Allegro. I got it set up and I linked to the allegro lib files but still got similar errors. Eventually I learn I needed the allegro dll file available.

In short is there a bzip dll file that is needed? Or are you confident the bzip lib files are in the lib path? Are the bzip.h file(s) included in the cpp file and in the include path?

Just thinking out loud.

Ace

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

AceBlkwell
Member #13,038
July 2011
avatar

Edgar, you are correct. I remember now. I got linker errors with out the dll file. The program compiled fine. However I did get a lot of undefined errors when I didn’t have the various paths set correctly and allegro files available. In Sean’s case bzip2 files.

Just brainstorming.

iheartcoffee
Member #16,518
August 2016
avatar

Thanks everyone. I had to link it to harfbuzz and bzip2 libraries and it worked.

Go to: