Allegro.cc - Online Community

Allegro.cc Forums » Installation, Setup & Configuration » How to compile for a release from linux for all linux platforms?

This thread is locked; no one can reply to it. rss feed Print
How to compile for a release from linux for all linux platforms?
Ori553
Member #15,835
December 2014

Hi :) that's my first post here, but I've been suggesting allegro to people for a few years.
I have a chess program that I made with allegro4.4 a couple of years ago, so I published it on sourceforce by compiling it for both windows and linux, (Sconvolt chess). I'm a linux boob, So today I downloaded it to see if it works, the windows executable works, but when I tried the linux version (by typing ./Sconvolt )
it says "./Sconvolt: error while loading shared libraries: liballeg.so.4.4: cannot open shared object file: No such file or directory"

So I discovered it hasn't been working for the last 2 years, so this means I disappointed the 1/week downloader from linux that tried my program.

so I downloaded allegro 4.4, followed the instructions:
mkdir Build, cd Build, cmake ..
make, make install

so I tried it again ./Sconvolt:
"./Sconvolt: error while loading shared libraries: liballeg.so.4.4: cannot open shared object file: No such file or directory"

So I tried to compile it again with:
g++ Sconvolt.cpp -o myprogram `allegro-config --libs`
this worked! so I typed ./myprogram and it works

now my question is: I'd like to create a linux executable so that anyone downloading my program can just type ./Sconvolt and have it work without having to install anything, how can I do that? what commands should I use?
please bare in mind that I have just some basic familiarity with linux, so if you could give me the exact g++ line that would be great, so I'd have a ground for learning

thanks for any help I might get

Arthur Kalliokoski
Second in Command
February 2005
avatar

Elias came up witha good solution to that a while ago.

They all watch too much MSNBC... they get ideas.

Ori553
Member #15,835
December 2014

I have no idea about what is "liballegro-monolith.so" or where to find it.

But I copied liballeg.so.4.4 in my game's folder, renamed Sconvolt to Sconvolt.bin, created a file startSconvoltLinux and put:
LD_LIBRARY_PATH=`pwd` ./Sconvolt.bin

so I tried to run ./startSconvoltLinux it works.
But then, I tried to run it from Knoppix, it says

Sconvolt.bin, cannot execute binary file

can a good soul just tell me what to do? I am still a linux beginner

Arthur Kalliokoski
Second in Command
February 2005
avatar

Ori553 said:

Sconvolt.bin, cannot execute binary file

My best guess: Sconvolt.bin is a 64 bit executable, but Knoppix is 32 bit.

Show the output of "stat Sconvolt.bin" and "file Sconvolt.bin" if you would.

[EDIT]

Building the monolithic library is an option in Cmake when you compile allegro. (WANT_MONOLITH)

They all watch too much MSNBC... they get ideas.

Ori553
Member #15,835
December 2014

ori@ori-300E4C-300E5C-300E7C:~/Desktop/sconvolt/Sconvolt_Chess$ stat ./Sconvolt.bin
File: ‘./Sconvolt.bin’
Size: 45744 Blocks: 96 IO Block: 4096 regular file
Device: 806h/2054d Inode: 683538 Links: 1
Access: (0775/-rwxrwxr-x) Uid: ( 1000/ ori) Gid: ( 1000/ ori)
Access: 2014-12-22 21:33:31.576317308 +0000
Modify: 2014-12-22 21:33:17.684154488 +0000
Change: 2014-12-22 21:33:17.684154488 +0000
Birth: -

ori@ori-300E4C-300E5C-300E7C:~/Desktop/sconvolt/Sconvolt_Chess$ file Sconvolt.bin
Sconvolt.bin: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.32, BuildID[sha1]=c67a5d8693f485bac02aa8ebfca6cc04f9d6eef3, not stripped

Arthur Kalliokoski
Second in Command
February 2005
avatar

Ori553 said:

Sconvolt.bin: ELF 64-bit LSB executable

So if the Knoppix live CD is 32 bit, it can't run Sconvolt.bin. If you compiled everything as 32 bit then it would probably work. IIRC, you can compile 32 bit progs from gcc by using the -m switch, but it'd probably be easier to do it in a virtual machine using a 32 bit distro. Of course, this implies that anybody trying to run it on a 64 bit distro would have the 32 bit compatibility libraries, which is usually the case. Maybe you could provide both versions?

They all watch too much MSNBC... they get ideas.

Ori553
Member #15,835
December 2014

I tried to run it both on Knoppix and Knoppix64bit (on a 64 bit machine), it says the same

then I tried it on Ubuntu Live CD, and it works.. I have no idea why it works on Ubuntu and not on Knoppix, I can't believe there isn't a striaghtforward way, how do other allegro projects have their releases?

so my best bet would be to compile it from a 32 bit virtual machine?

Arthur Kalliokoski
Second in Command
February 2005
avatar

If it doesn't run on Knoppix 64 bit, I don't know what the trouble is.

They all watch too much MSNBC... they get ideas.

Ori553
Member #15,835
December 2014

I will try to compile it for 32 bits

bamccaig
Member #7,536
July 2006
avatar

There are a few things you'll have to check.

  • The file mode to make sure everything that needs to be executable is.

  • Obviously the processor architecture as Arthur pointed out.

  • The Allegro shared object library or your own program may have additional dependencies, which may not exactly match what is available on each system, so to be safe you'd have to distribute those as well.

  • If your distro uses SELinux then you may have to make sure the appropriate context is applied to your files and/or the device they are on.

For the dependencies check the output of ldd ./liballeg.so.4.4 and ldd ./Sconvolt.bin. Those should list mandatory dynamically loaded libraries that are loaded by the linker at run-time. They typically have paths in them. IIRC, those paths can be either absolute or relative. Make sure whatever paths they are have matches within the system you're trying to run on. If not you may need to copy libraries to a relative path in order to link with them. I'm not 100% sure what the difference is between relative and absolute paths when linking.

bambams@test-chamber-1:~/src$ cd ldd-example/
bambams@test-chamber-1:~/src/ldd-example$ ls -la
total 20
drwx------  2 bambams bambams 4096 Dec 24 16:18 .
drwx--x--x 65 bambams bambams 4096 Dec 24 16:18 ..
-rw-------  1 bambams bambams   76 Dec 24 16:11 main.c
-rw-------  1 bambams bambams  190 Dec 24 16:17 Makefile
-rw-------  1 bambams bambams   78 Dec 24 16:09 so.c
bambams@test-chamber-1:~/src/ldd-example$ make
gcc -c -fPIC -Wall -o so.o so.c
gcc -o libmy.so -shared -Wl,-soname,libmy.so so.o
gcc -c -fPIC -Wall -o main.o main.c
gcc -o a.out libmy.so main.o
bambams@test-chamber-1:~/src/ldd-example$ ls -la
total 44
drwx------  2 bambams bambams 4096 Dec 24 16:18 .
drwx--x--x 65 bambams bambams 4096 Dec 24 16:18 ..
-rwx------  1 bambams bambams 7138 Dec 24 16:18 a.out
-rwx------  1 bambams bambams 6432 Dec 24 16:18 libmy.so
-rw-------  1 bambams bambams   76 Dec 24 16:11 main.c
-rw-------  1 bambams bambams 1400 Dec 24 16:18 main.o
-rw-------  1 bambams bambams  190 Dec 24 16:17 Makefile
-rw-------  1 bambams bambams   78 Dec 24 16:09 so.c
-rw-------  1 bambams bambams 1520 Dec 24 16:18 so.o
bambams@test-chamber-1:~/src/ldd-example$ LD_LIBRARY_PATH=$(pwd) ./a.out
Hello
bambams@test-chamber-1:~/src/ldd-example$ ldd ./libmy.so ./a.out 
./libmy.so:
	linux-vdso.so.1 =>  (0x00007fff13f8b000)
	libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f358a019000)
	/lib64/ld-linux-x86-64.so.2 (0x00007f358a5b3000)
./a.out:
	linux-vdso.so.1 =>  (0x00007fffb09c5000)
	libmy.so => not found
	libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007fb12e9b5000)
	/lib64/ld-linux-x86-64.so.2 (0x00007fb12ed4e000)
bambams@test-chamber-1:~/src/ldd-example$ LD_LIBRARY_PATH=$(pwd) ldd ./a.out 
	linux-vdso.so.1 =>  (0x00007ffff99e9000)
	libmy.so => /home/bambams/src/ldd-example/libmy.so (0x00007fdcc5333000)
	libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007fdcc4f9c000)
	/lib64/ld-linux-x86-64.so.2 (0x00007fdcc5536000)
bambams@test-chamber-1:~/src/ldd-example$ 

It's really rather silly to distribute shared object files like this though. They're intended to be shared, but when they're bundled like this they tend not to be. You're better off just statically linking when possible. That said, I'm not sure how easy or difficult it is to statically link an Allegro program. I suppose it depends on how hard the dependencies are to statically link too. :-/

Arthur Kalliokoski
Second in Command
February 2005
avatar

A few months ago, Linux Mint wouldn't run programs compiled under Slackware 14.1 because the glibc version differed.

They all watch too much MSNBC... they get ideas.

Go to: