Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » Ubuntu 18.04 Allegro 5 on Codeblocks

This thread is locked; no one can reply to it. rss feed Print
Ubuntu 18.04 Allegro 5 on Codeblocks
Matias Persson
Member #15,093
May 2013

Following this guide https://wiki.allegro.cc/index.php?title=Install_Allegro_from_Ubuntu_PPAs

And even trying to build it from source https://wiki.allegro.cc/index.php?title=Install_Allegro5_From_Git/Linux/Debian

neither works.
I can compile my program AND run just fine in terminal, but in Codeblocks I can only manage to compile it linking to Allegro dynamically, however upon running the program console error: Segmentation fault (core dumped)

I cannot at all compile when linking statically.
My goal is to actually compile the program linking to Allegro statically, because I want to distribute the game without having to distribute the Allegro binaries alongside the game.

Please help!

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

Yet another victim of static linking on Linux. :/

The short answer is, don't.

It's far easier to distribute a set of .so files and set LD_LIBRARY_PATH at runtime to load them.

Otherwise, you're in for a heap of hurt. There is no such thing as a fully statically linked executable in Linux due to all the different library versions available that have to be linked dynamically.

Or give users a script that installs the dependencies for you before first run.

There was a talk about this on IRC and there is another solution I can't remember at the moment. Someone please chime in here. It allowed you to distribute a single file to multiple distros.

Matias Persson
Member #15,093
May 2013

Nevermind the static linking. What if I want to dynamic link the library, seeing as I was just told that Steam requires dynamic linking too.
When I run the program I compiled using dynamic linking I get segmentation fault (core dumped). Why is that?

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

It's not the linking causing the seg fault, it's your code, likely the current working directory is wrong when run from inside code blocks.

You can set the project cwd with the following; Go to Menu->Project->Build Settings->Executable working directory and change it.

Then your program will find your runtime dependencies.

You can also fix your program by setting the cwd programmatically.

Try a debugger like gdb. It will tell you exactly why it is throwing a seg fault.

Ariesnl
Member #2,902
November 2002
avatar

It's far easier to distribute a set of .so files and set LD_LIBRARY_PATH at runtime to load them.

Could you explain this in detail ?
Or is there a goor tutorial on how to distribute/write for linux with allegro ?

I managed to get it richt with static linking once... but just once ::)

( Ant I want to get rid of windows, since Win 10 my HDD thinks it's a jet engine with afterburner :-/)

Perhaps one day we will find that the human factor is more complicated than space and time (Jean luc Picard)
Current project: [Star Trek Project ] Join if you want ;-)

GullRaDriel
Member #3,861
September 2003
avatar

Commonly you add your env to the library path just before launching, like:

export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/your/custom/path/

In a .sh script, admitting you put all the .so in a lib directory:

#!/bin/sh
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:./lib/
./my_super_binary -o my_options_if_any
exit $?  #return the launched proc exit code

Edit:
Don't forget to chmod +x or +X , and ./my_script.sh to start with the good env

"Code is like shit - it only smells if it is not yours"
Allegro Wiki, full of examples and articles !!

Ariesnl
Member #2,902
November 2002
avatar

I read something about setting the rPath for the executable..
is that recommended in linux ?

Perhaps one day we will find that the human factor is more complicated than space and time (Jean luc Picard)
Current project: [Star Trek Project ] Join if you want ;-)

GullRaDriel
Member #3,861
September 2003
avatar

I don't know. I never use it or see it a lot.

"Code is like shit - it only smells if it is not yours"
Allegro Wiki, full of examples and articles !!

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

Go to: