Allegro.cc - Online Community

Allegro.cc Forums » Installation, Setup & Configuration » Trying to make static build in linux

This thread is locked; no one can reply to it. rss feed Print
Trying to make static build in linux
Pinbot
Member #16,613
December 2016

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

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

Pinbot
Member #16,613
December 2016

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

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

Eric Johnson
Member #14,841
January 2013
avatar

Check out this article on the wiki for a list of Linux (Debian variants) dependencies.

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

Eric Johnson
Member #14,841
January 2013
avatar

My mistake. :-[

EliasYFGM
Member #11,096
June 2009

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.

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

Pinbot
Member #16,613
December 2016

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.

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

Pinbot
Member #16,613
December 2016

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!

Thomas Fjellstrom
Member #476
June 2000
avatar

It's -lalleg not -liballeg

--
Thomas Fjellstrom - [website] - [email] - [Allegro Wiki] - [Allegro TODO]
"If you can't think of a better solution, don't try to make a better solution." -- weapon_S
"The less evidence we have for what we believe is certain, the more violently we defend beliefs against those who don't agree" -- https://twitter.com/neiltyson/status/592870205409353730

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

Thomas Fjellstrom
Member #476
June 2000
avatar

Also that...

--
Thomas Fjellstrom - [website] - [email] - [Allegro Wiki] - [Allegro TODO]
"If you can't think of a better solution, don't try to make a better solution." -- weapon_S
"The less evidence we have for what we believe is certain, the more violently we defend beliefs against those who don't agree" -- https://twitter.com/neiltyson/status/592870205409353730

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

Pinbot
Member #16,613
December 2016

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.

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

Pinbot
Member #16,613
December 2016

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.

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

Pinbot
Member #16,613
December 2016

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

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

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.

Pinbot
Member #16,613
December 2016

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.

amarillion
Member #940
January 2001
avatar

Pinbot said:

/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

Pinbot
Member #16,613
December 2016

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

Go to: