Allegro.cc - Online Community

Allegro.cc Forums » Installation, Setup & Configuration » static linking on linux

This thread is locked; no one can reply to it. rss feed Print
static linking on linux
Michael Weiss
Member #223
April 2000

I am having troubles statically linking on linux.

I have done both dynamic and static on windows.
For static I needed to add a long list of static dependencies.
I found a few places where people shared their version of that list.

Now I'm trying to do the same on linux (ubuntu 16.04.4)
and I'm getting lots of undefined references at link time
which I'm pretty sure is because I don't have the long list
of static dependencies that I need for linux.

I have searched the allegro.cc forums and found this post:

https://www.allegro.cc/forums/thread/613797

where Edgar Reynaldo says:

...you're gonna have to link to a bunch of static system libraries, which I don't have the list for for Unix, but I do for Windows somewhere here...

Can someone point me in the right direction?

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

You need pkg-config to get the list of libraries to link.

g++ -Wall -g -o RunMe `pkg-config --static --cflags allegro_monolith-5` *.cpp -static `pkg-config --static --libs allegro_monolith-5`

Although to be honest static linking on Linux is a nightmare. You're better off distributing .so's like dll's and providing a run script to set the LD_LIBRARY_PATH at run time so the libraries are picked up before system libraries.

Michael Weiss
Member #223
April 2000

Thanks Edgar,

I already had a script to run my game like that:

LD_LIBRARY_PATH=./linux_libs ./pm

and it looks like I only had to include:

liballegro_monolith.so.5.2
libdumb.so.1

I was just wondering if static linking would be a more elegant approach...

But I am stretching the limits of what I understand here and will
take your word for it that static linking on linux is more complicated
than I care to get in to...

Thanks again :)

Chris Katko
Member #1,881
January 2002
avatar

Although to be honest static linking on Linux is a nightmare.

Why?

-----sig:
“Programs should be written for people to read, and only incidentally for machines to execute.” - Structure and Interpretation of Computer Programs
"Political Correctness is fascism disguised as manners" --George Carlin

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

Because some of the system libraries aren't static. Which makes linking fail if you don't interleave '-static' and '-shared' all over the link line. That also means if they don't have the required system libraries installed, then it won't run. static linking on linux sucks.

EDIT
I'm about to try to static link my Skyline game on Linux. I'll report back how it goes.

Go to: