Hi, I need help to make static build of my program using allegro 4.
I compile with this command line:
g++ program.cpp `allegro-config --libs` -o program
and have this as my first line in program:
#define ALLEGRO_STATICLINK
compiles but not static build, what do I need to do?
Running linux mint btw.
Thanks
Try allegro-config --help. There should be a --static option that you pass into your commands to build statically.
Thanks Edgar
So running command line:
g++ program.cpp `allegro-config --libs --static` -o program
returns:
/usr/bin/ld: cannot find -lasound
I'm thinking static libraries aren't built?
I'm pretty new to linux and was previously using allegro
in windows with an IDE so not sure how to build the libraries if
thats the problem.
Thanks
You need to install the dependencies too. I don't know what's required for linux.
Check out this article on the wiki for a list of Linux (Debian variants) dependencies.
He's using Allegro 4.
My mistake.
For -lasound you need to install libasound2-dev. I'm not really sure what other libraries it needs to compile statically though.
I'm having a similar problem with the --static option, but with -lXxf86dga missing.
Search for libXxf86dga.a in your package manager's search function.
Thanks Edgar, Software manager didn't find "libXxf86dga.a" but did show
libXxf86dga-dev (already installed) and
libXxf86dg1 (also installed)
libXxf86dg1-dbg (debug package, not installed)
I reinstalled a allegro 4.4 from the source files. Previous install
was from mint package manager. Now it compiles without any messages
mentioned earlier but still not producing a static file.
Did you compile the static version of allegro? -DSHARED=Off Try passing -static before the allegro-config parameter as well.
I have recompiled the allegro source with -DSHARED=Off and the
static libraries are built liballeg.a etc, but the results are
the same.
Try passing -static before the allegro-config parameter as well.
This will produce a bunch of LibX11 library errors.
if I try:
g++ program.cpp -lliballeg `allegro-config --libs --static` -o program
it returns: /usr/bin/ld: cannot find -liballeg
liballeg.a is in /usr/bin also copied it to /usr/lib and /usr/local/lib
also /usr/local/bin
and it still can't find it!
It's -lalleg not -liballeg
You don't need -lalleg if you're using allegro-config.
Also that...
Don't you need to pass --cflags to allegro-config as well?
Thanks guys
It's -lalleg not -liballeg
You are correct thank you
You don't need -lalleg if you're using allegro-config.
I know, I was linking outside of allegro-config to verify that it could
find the library, and now it does using -lalleg
Don't you need to pass --cflags to allegro-config as well?
now using --cflags and still no static build.
You need to post the transcript of what it says. What do you mean, no static build? No build? Or a build that depends on dynamic libraries? You have to be clear, we can't read minds, and we can't help without information.
The program compiles fine, no messages.
Builds the same non static file thats made without the --static option.
I'm strictly going by file size, programs file size is 53kb either way.
When compiled on windows machine --static built size is 1200kb.
Please post the output of `allegro-config --cflags --libs --static` by itself. You may need to use echo.
echo `allegro-config --cflags --libs --static`
-I/usr/local/include -L/usr/local/lib -lalleg -lm -lpthread -lrt -lSM -lICE -lX11 -lXext -lXext -lXcursor -lXcursor -lXpm -lXxf86vm -lXxf86dga -lSM -lICE -lX11 -lXext -ldl
Now try using that same command line with '-static' in front of it. You may have to add in '-shared' and '-static' in-between some of the libs to get it to compile. The problem is that gcc dynamic links by default, so if there is a shared library with the same name, it will default to the shared library. When you use the -static flag it tells gcc to only link to static libs, and when you use -shared, it will only link to shared libs.
Static linking in Linux is always a pain, but you will have to explore and experiment a little bit to get it to work.
Post errors and or results.
Ok, I tried that method a few dozen times with different variations (all producing lots of errors). I then installed a different linux (linux lite) on new partition,
then installed allegro4 from package manager, which worked dynamicly no problem.
The --static build would not work but did produce an error at least
/usr/bin/ld: cannot find -lasound
/usr/bin/ld: cannot find -lXxf86dga
collect2: error: ld returned 1 exit status
I did have xf86dga-dev installed btw.
I then uninstalled allegro and reinstalled via sudo apt-get (not sure if they are the same) but the results were.
Then uninstalled that and downloaded and compiled source files and It worked!
I now have a 3100kb file vs 53kb. And no errors!
I still want to get it working on linux mint though.
BTW I installed allegro 5 on linux mint just to see if it would work
and I was able to make static build.
/usr/bin/ld: cannot find -lasound
Problem here is that it's trying to statically link every library (not just allegro, but every library that you are passing to the linker). For some you only have the dynamic ones available.
You can try adding -static (or -Wl,-Bstatic, seems to be the same thing) before allegro and -dynamic before the rest.
For example:
-I/usr/local/include -L/usr/local/lib -static -lalleg -dynamic -lm -lpthread -lrt -lSM -lICE -lX11 -lXext -lXext -lXcursor -lXcursor -lXpm -lXxf86vm -lXxf86dga -lSM -lICE -lX11 -lXext -ldl
Thanks amarillion.
Just to update, I have now tried building allegro 4
on several linux distros here is a summary of whats working
as far as static builds...
Linux Lite: working!
Mint Cinnamon: Fail! (shared builds only)
Mint Mate: Working!
Mint KDE: will build static build but file is 2.3mb(should be 3.1mb) exe not run
Zorin: Same results as Mint KDE