|
Compilation errors with static library |
Alexander Zhirov
Member #17,695
May 2020
|
When compiling with a static library, I get a bunch of errors. Here is the compilation log file. It seems as if the allegro_monolith-static library contains paths to the source files. Do I need to specify something? P.S. I use the operating system Windows 7. |
Peter Hull
Member #1,136
March 2001
|
If you're static linking you need to specify all the libraries at link time. This might help:
|
Alexander Zhirov
Member #17,695
May 2020
|
I just have a bunch of questions. I want to figure it out, but nowhere can I find information about it. 1) As I understand it, to compile into a static file you need to use the allegro library with the tail of statics? Too many questions and too few answers. Very little library information. As I understand it, 2D is of little interest to anyone. But I'm very interested and I want to figure it out. I do not program much, but I am very interested in doing this using the allegro library. |
SiegeLord
Member #7,827
October 2006
|
First of all, I'd avoid static linking, it's too much of a headache. Bundle the shared libraries you want to use with your application, it's far easier. On Linux, you can use LD_LIBRARY_PATH to tell the dynamic linker where to find your bundled shared libraries. But... if you insist on doing static linking, here are a few answers to your questions. Alexander Zhirov said: 1) As I understand it, to compile into a static file you need to use the allegro library with the tail of statics? Yes. Quote: 2) If so, then why are additional third-party libraries used for compilation if all of this is already present in the allegro? They're not. Allegro static libraries only contain Allegro's objects. The dependencies (and system libraries) are linked separately. Quote: 3) Can I take a look at a specific example of compiling into a static file? Here's an example build command to compile a binary statically linked to Allegro, and the runtime libraries using MSYS2. This assumes you've extracted the include and lib directories from official binary packages in the same directory: g++ main.cpp -o bin/main.exe -Llib -Iinclude -static-libgcc -static-libstdc++ -static -lpthread \ -lallegro_monolith-static -ldumb -lFLAC -lfreetype -ljpeg \ -lopusfile -lopus -lphysfs -lpng16 -ltheoradec \ -lvorbis -lvorbisfile -logg -lwebp -lzlib \ -ldsound -lopengl32 -luser32 -lgdi32 -lcomdlg32 \ -lole32 -lwinmm -lkernel32 -lpsapi -lshlwapi
Quote: 4) Why are static libraries used separately for audio/font/image, and so on, if there is one monolithic file? No particular reason. Quote: 5) If I compile on Linux and want to use the compiled executable file on another computer, then how can I compile to a static file? I understand that Linux does not have a static Allegro library? You need to compile the static dependencies and static Allegro yourself. "For in much wisdom is much grief: and he that increases knowledge increases sorrow."-Ecclesiastes 1:18 |
GullRaDriel
Member #3,861
September 2003
|
Say, if I want to have a clean directory setup like this: prog/exectuable On linux I would have to use a shell script to ease the starting. That script would set up LD_LIBRARY_PATH and add /prog/shared. On windows I don't know how I can make this work. Maybe a batch script adding /prog/shared to the PATH ? "Code is like shit - it only smells if it is not yours" |
Alexander Zhirov
Member #17,695
May 2020
|
I managed to compile using THIS library package. Initially, I thought of downloading each library individually, but then again I carefully looked at everything on the main site. I managed to successfully compile using these keys: 1-lallegro_monolith-static -static -ljpeg -ldumb -lwebp \
2-lFLAC -lvorbisfile -lvorbis -logg -lphysfs -lfreetype \
3-lpng16 -ldsound -lgdiplus -luuid -lkernel32 -lwinmm \
4-lpsapi -lopengl32 -lglu32 -luser32 -lcomdlg32 -lgdi32 \
5-lshell32 -lole32 -ladvapi32 -lws2_32 -lshlwapi -lpthread \
6-static-libstdc++ -static-libgcc -lz -lopusfile -lopus
or 2-lallegro_dialog-static -lallegro_acodec-static -lallegro_audio-static \
3-lallegro_image-static -lallegro_primitives-static -lallegro_ttf-static \
4-lallegro_font-static -lallegro-static -static -ljpeg -ldumb -lwebp -lFLAC \
5-lvorbisfile -lvorbis -logg -lphysfs -lfreetype -lpng16 -ldsound -lgdiplus \
6-luuid -lkernel32 -lwinmm -lpsapi -lopengl32 -lglu32 -luser32 -lcomdlg32 \
7-lgdi32 -lshell32 -lole32 -ladvapi32 -lws2_32 -lshlwapi -lpthread \
8-static-libstdc++ -static-libgcc -lz -lopusfile -lopus
Compilation result: 3cd 'C:\Users\alexander\Documents\NetBeansProjects\Allegro_test'
4C:\mingw64\bin\make.exe -f Makefile CONF=Release
5"/C/mingw64/bin/make.exe" -f nbproject/Makefile-Release.mk QMAKE= SUBPROJECTS= .build-conf
6make[1]: Entering directory `C:/Users/alexander/Documents/NetBeansProjects/Allegro_test'
7"C:/mingw64/bin/make.exe" -f nbproject/Makefile-Release.mk dist/Release/MinGW-Windows/allegro_test.exe
8make[2]: Entering directory `C:/Users/alexander/Documents/NetBeansProjects/Allegro_test'
9mkdir -p build/Release/MinGW-Windows
10rm -f "build/Release/MinGW-Windows/main.o.d"
11g++ -m64 -c -O3 -I/C/allegro/static/include -include /C/Users/alexander/Documents/NetBeansProjects/Allegro_test/object.h -std=c11 -MMD -MP -MF "build/Release/MinGW-Windows/main.o.d" -o build/Release/MinGW-Windows/main.o main.c
12cc1plus.exe: warning: command line option '-std=c11' is valid for C/ObjC but not for C++
13mkdir -p dist/Release/MinGW-Windows
14g++ -o dist/Release/MinGW-Windows/allegro_test build/Release/MinGW-Windows/main.o -L../../../../../allegro/static/lib -lallegro_monolith-static -static -ljpeg -ldumb -lwebp -lFLAC -lvorbisfile -lvorbis -logg -lphysfs -lfreetype -lpng16 -ldsound -lgdiplus -luuid -lkernel32 -lwinmm -lpsapi -lopengl32 -lglu32 -luser32 -lcomdlg32 -lgdi32 -lshell32 -lole32 -ladvapi32 -lws2_32 -lshlwapi -lpthread -static-libstdc++ -static-libgcc -lz -lopusfile -lopus
15make[2]: Leaving directory `C:/Users/alexander/Documents/NetBeansProjects/Allegro_test'
16make[1]: Leaving directory `C:/Users/alexander/Documents/NetBeansProjects/Allegro_test'
17
18MAKE SUCCESSFUL ( : 9s)
Through gcc, the compiler wrote errors to me. I tried compiling through g++ and the errors disappeared. Why does compilation happen through g++? Why not through gcc? Compilation errors via gcc: 4cd 'C:\Users\alexander\Documents\NetBeansProjects\Allegro_test'
5C:\mingw64\bin\make.exe -f Makefile CONF=Release
6"/C/mingw64/bin/make.exe" -f nbproject/Makefile-Release.mk QMAKE= SUBPROJECTS= .build-conf
7make[1]: Entering directory `C:/Users/alexander/Documents/NetBeansProjects/Allegro_test'
8"C:/mingw64/bin/make.exe" -f nbproject/Makefile-Release.mk dist/Release/MinGW-Windows/allegro_test.exe
9make[2]: Entering directory `C:/Users/alexander/Documents/NetBeansProjects/Allegro_test'
10mkdir -p build/Release/MinGW-Windows
11rm -f "build/Release/MinGW-Windows/main.o.d"
12gcc -m64 -c -O3 -I/C/allegro/static/include -include /C/Users/alexander/Documents/NetBeansProjects/Allegro_test/object.h -std=c11 -MMD -MP -MF "build/Release/MinGW-Windows/main.o.d" -o build/Release/MinGW-Windows/main.o main.c
13mkdir -p dist/Release/MinGW-Windows
14gcc -o dist/Release/MinGW-Windows/allegro_test build/Release/MinGW-Windows/main.o -L../../../../../allegro/static/lib -lallegro_dialog-static -lallegro_acodec-static -lallegro_audio-static -lallegro_image-static -lallegro_primitives-static -lallegro_ttf-static -lallegro_font-static -lallegro-static -static -ljpeg -ldumb -lwebp -lFLAC -lvorbisfile -lvorbis -logg -lphysfs -lfreetype -lpng16 -ldsound -lgdiplus -luuid -lkernel32 -lwinmm -lpsapi -lopengl32 -lglu32 -luser32 -lcomdlg32 -lgdi32 -lshell32 -lole32 -ladvapi32 -lws2_32 -lshlwapi -lpthread -static-libstdc++ -static-libgcc -lz -lopusfile -lopus
15../../../../../allegro/static/lib\liballegro-static.a(d3d_display_formats.cpp.obj): In function `_al_d3d_generate_display_format_list':
16C:/dev/allegro_winpkg/universal/allegro/src/win/d3d_display_formats.cpp:49: undefined reference to `__cxa_guard_acquire'
17C:/dev/allegro_winpkg/universal/allegro/src/win/d3d_display_formats.cpp:50: undefined reference to `__cxa_guard_acquire'
18C:/dev/allegro_winpkg/universal/allegro/src/win/d3d_display_formats.cpp:50: undefined reference to `__cxa_guard_release'
19C:/dev/allegro_winpkg/universal/allegro/src/win/d3d_display_formats.cpp:49: undefined reference to `__cxa_guard_release'
20C:/dev/allegro_winpkg/universal/allegro/src/win/d3d_display_formats.cpp:49: undefined reference to `__cxa_guard_abort'
21C:/dev/allegro_winpkg/universal/allegro/src/win/d3d_display_formats.cpp:50: undefined reference to `__cxa_guard_abort'
22../../../../../allegro/static/lib\liballegro-static.a(d3d_display_formats.cpp.obj):d3d_display_formats.cpp:(.xdata+0x2c): undefined reference to `__gxx_personality_seh0'
23collect2.exe: error: ld returned 1 exit status
24make[2]: *** [dist/Release/MinGW-Windows/allegro_test.exe] Error 1
25make[2]: Leaving directory `C:/Users/alexander/Documents/NetBeansProjects/Allegro_test'
26make[1]: *** [.build-conf] Error 2
27make[1]: Leaving directory `C:/Users/alexander/Documents/NetBeansProjects/Allegro_test'
28make: *** [.build-impl] Error 2
29
30MAKE FAILED
And one moment. When i run the compiled executable file, the command line window starts simultaneously. So it should be? If not, how to avoid this? I do not use debugging information during compilation. |
GullRaDriel
Member #3,861
September 2003
|
Add -mwindows to compile flags to get rid of the console (IIRC) "Code is like shit - it only smells if it is not yours" |
Alexander Zhirov
Member #17,695
May 2020
|
GullRaDriel said: GullRaDriel: Yes, that helped. Many thanks. I simply do not have programming experience in Windows (I hate this system:-X). But, why does compilation happen through g++? Why not through gcc? I supplement the post: Without the -static key, my project compiles and runs on Linux. When compiling on Linux using the -static key, gcc produces these errors: 1username@pc ~ $ gcc -static -lallegro_dialog -lallegro_acodec -lallegro_audio -lallegro_image -lallegro_primitives -lallegro_ttf -lallegro_font -lallegro -O3 -include objects.h -std=c11 main.c
2/usr/bin/ld: impossible to find -lallegro_dialog
3/usr/bin/ld: impossible to find -lallegro_acodec
4/usr/bin/ld: impossible to find -lallegro_audio
5/usr/bin/ld: impossible to find -lallegro_image
6/usr/bin/ld: impossible to find -lallegro_primitives
7/usr/bin/ld: impossible to find -lallegro_ttf
8/usr/bin/ld: impossible to find -lallegro_font
9/usr/bin/ld: impossible to find -lallegro
10collect2: error: ld execution failed with return code 1
I have the allegro-devel package installed. Here i need to specify other keys when compiling into a static executable? Does anyone have any opinions why this is happening? |
Edgar Reynaldo
Major Reynaldo
May 2007
|
Most people don't static link on Linux. Because it's very hard to get right. It looks like you don't have the static libraries installed. allegro-devel may not provide static libs on linux. You can build them yourself if this is the case. Most people just bundle .so files on Linux and set LD_LIBRARY_PATH to include them at runtime. My Website! | EAGLE GUI Library Demos | My Deviant Art Gallery | Spiraloid Preview | A4 FontMaker | Skyline! (Missile Defense) Eagle and Allegro 5 binaries | Older Allegro 4 and 5 binaries | Allegro 5 compile guide |
Alexander Zhirov
Member #17,695
May 2020
|
Edgar Reynaldo said: Most people just bundle .so files on Linux and set LD_LIBRARY_PATH to include them at runtime. Yes, I already have * .so packages installed. So, using allegro-devel, can I create * .a allegro library archives? And then create a static executable based on them? I understand that this may seem like the wrong solution, I just want to make an executable file that will not depend on libraries. |
Edgar Reynaldo
Major Reynaldo
May 2007
|
Alexander Zhirov said: So, using allegro-devel, can I create * .a allegro library archives? No, you'll have to build the static libraries yourself if they don't come with allegro-devel package. Alexander Zhirov said: I understand that this may seem like the wrong solution, I just want to make an executable file that will not depend on libraries. That's exceedingly difficult on Linux due to all the system libraries that don't come in static flavors. You can only link so much statically on Linux. My Website! | EAGLE GUI Library Demos | My Deviant Art Gallery | Spiraloid Preview | A4 FontMaker | Skyline! (Missile Defense) Eagle and Allegro 5 binaries | Older Allegro 4 and 5 binaries | Allegro 5 compile guide |
Alexander Zhirov
Member #17,695
May 2020
|
Edgar Reynaldo said: No, you'll have to build the static libraries yourself if they don't come with allegro-devel package. I mean: can I compile Allegro static libraries myself using the allegro-devel package? |
Peter Hull
Member #1,136
March 2001
|
Alexander Zhirov said: I mean: can I compile Allegro static libraries myself using the allegro-devel package? You'll need to compile all of allegro yourself from the source which you can get here: If you want my advice, it would be a better use of your time to develop a good game and then worry about distributing it.
|
|