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.
If you're static linking you need to specify all the libraries at link time. This might help:
https://github.com/liballeg/allegro_wiki/wiki/Static-Linking
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?
2) If so, then why are additional third-party libraries used for compilation if all of this is already present in the allegro?
3) Can I take a look at a specific example of compiling into a static file?
4) Why are static libraries used separately for audio/font/image, and so on, if there is one monolithic file?
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?
6) Can I see a specific example of compiling into a static executable in Linux?
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.
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.
1) As I understand it, to compile into a static file you need to use the allegro library with the tail of statics?
Yes.
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.
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
4) Why are static libraries used separately for audio/font/image, and so on, if there is one monolithic file?
No particular reason.
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.
Say, if I want to have a clean directory setup like this:
prog/exectuable
prog/shared/*.so or *.dll
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 ?
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:
or
Compilation result:
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:
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.
Add -mwindows to compile flags to get rid of the console (IIRC)
GullRaDriel:
Add -mwindows to compile flags to get rid of the console (IIRC)
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:
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?
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.
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.
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.
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.
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?
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:
https://liballeg.org/download.html#source
Having the binaries from the allegro5-devel package won't help you (in fact might be confusing if they conflict with the allegro you've built yourself from source)
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.