Welcome, Guest. Please login or register.

Login with username, password and session length

 
Advanced search

1411678 Posts in 69399 Topics- by 58453 Members - Latest Member: Arktitus

May 17, 2024, 09:04:36 AM

Need hosting? Check out Digital Ocean
(more details in this thread)
TIGSource ForumsDeveloperTechnical (Moderator: ThemsAllTook)Releasing a game for Linux
Pages: [1] 2
Print
Author Topic: Releasing a game for Linux  (Read 5646 times)
JackieJay
Level 3
***



View Profile WWW
« on: April 01, 2010, 04:41:17 PM »

Well I a question.
I have ubunto, and I can compile my game in there.
Will the resulting executable work for all the distros ?  Blink.Blink
Logged

Average Software
Level 10
*****

Fleeing all W'rkncacnter


View Profile WWW
« Reply #1 on: April 01, 2010, 04:59:49 PM »

Well I a question.
I have ubunto, and I can compile my game in there.
Will the resulting executable work for all the distros ?  Blink.Blink

Most likely no.  For one thing, some distros use a different processor architecture, others have different versions of libraries in different locations, and so on.

Linux releases are generally done as source, and users compile it themselves, or you find someone to make packages for various distros.
Logged



What would John Carmack do?
lansing
Level 2
**


View Profile
« Reply #2 on: April 01, 2010, 05:58:31 PM »

Either that or compile for Windows and let people run it under Wine, that's more portable Tongue
Logged
mjau
Level 3
***



View Profile
« Reply #3 on: April 01, 2010, 06:03:13 PM »

For one thing, some distros use a different processor architecture,
I'm assuming we're talking about x86 here, which is what the vast majority uses.  (If you want to support ppc or arm or whatever too, fine, but you can worry about that later. Linux doesn't support fat executables (at least not officially), so they'll be different executables anyway.)

Quote
others have different versions of libraries in different locations, and so on.
Which is why including libraries is a good idea, similar to how you'd include .dlls in windows.

Quote
Linux releases are generally done as source, and users compile it themselves, or you find someone to make packages for various distros.
No.  Please stop saying this.  Even if he can release source, most Linux people like not having to compile everything too, and it's not an option for closed-source stuff in any case.

~

Anyway, it's very possible to make executables that run on pretty much all Linux distros (obviously only for compatible cpu architectures, and assuming the distro isn't extremely old), but you have to work a little more for it than just compiling and hoping it'll go.

First off, make sure your executable or any of the libraries you'll include doesn't depend on a too new version of glibc.  You can check this with objdump:

Code:
objdump -x my-executable | grep GLIBC

You'll get a list of glibc version numbers.  The highest of these is the minimum required glibc version that your game (and libraries, if you check those (which you should)) require to run.  If it's too high (i tend to go with around 2.3-2.3.6 max, but that's pretty old by now so you can probably go a little higher), you can use a little trick to build files that depend on an earlier version of glibc.  gcc unfortunately doesn't support this directly, but you can use gensymoverride to generate a special include file you can force-include with your compiles to force the earlier glibc.  Run gensymoverride without arguments for usage info.  Once you've got your header, use it by passing -include your-header.h to every gcc command (ie gcc -include overrides.h ...).  I recommend setting up a script to do this for you and set that script as the compiler to use.  Remember you'll have to do this for any offending libraries you use as well.  When done, double-check that it worked with objdump again as above.

Secondly, statically link what you can.  Do not statically link glibc, but if you use libstdc++ and don't use any dynamically linked libraries that use c++, you can statically link that if you want (get the static version of libstdc++ with "g++ -print-file-name=libstdc++.a", and pass "-static-libgcc" and "-Wl,--as-needed" when linking. if unsure just include the libstdc++ .so with your package like any other lib).

Thirdly, include all dynamic dependencies in the download, except for glibc (again, don't statically link this), X (parts of this can be statically linked, but leave the .so's), or libgcc_s.so (can be safely statically linked with -static-libgcc if you also either don't use libstdc++ or statically link it as well).  Check what your executable and libraries depend on with ldd (all dependencies, recursive) or objdump (direct dependencies only):
Code:
ldd my-executable
objdump -x my-executable | grep NEEDED
This isn't anything special btw; you include .dlls for Windows, you include .so's for Linux.  Unlike windows though, linux doesn't load libraries from the executable's directory by default, so you have to tell it to do that. You can either use a wrapper script that sets LD_LIBRARY_PATH to the path where they can be located (works similar to PATH) and then executes your real executable, or you can set RPATH on your main executable using a path relative to '$ORIGIN' where origin is expanded to the executable's containing directory by the linker.  Pass -Wl,-rpath,$ORIGIN to gcc to do that, but remember to protect $ORIGIN from the shell and make etc, or they'll think it's an environment variable and ruin everything.  You can verify that you did it right by checking for RPATH with objdump:
Code:
objdump -x my-executable | grep RPATH
If it's missing the $ORIGIN part or is set to "RIGIN" or something you didn't protect $ORIGIN sufficiently from the shell/make/etc.  Also, running ldd on an execuable with rpath set in this way will use the rpath to locate the libraries, so you can verify that you did everything right with that.

Fourthly, make sure that libraries you include do not have an absolute RPATH, as this may prevent them from working unless installed in that particular location, which you obviously don't want.  Check with objdump -x my-executable | grep RPATH as for executables.  (Rpaths relative to $ORIGIN like for the executable are fine.)

Fiftly, make sure you've covered dynamic runtime-loaded libraries (ie anything loaded with dlopen at runtime) as well, and that your executable can locate them.  RPATH doesn't update the path used by dlopen, LD_LIBRARY_PATH does, so if you use the RPATH way to locate libraries to avoid the wrapper script your executable may set LD_LIBRARY_PATH to be sure these can be located.  Detecting runtime-loaded libraries is a bit more tricky since they won't be listed by ldd or objdump, you'll just have to read the documentation of the things you use.  An example of this is SDL_mixer which can load libogg, libvorbis and libvorbisfile at runtime (though it can be configured to depend on them "normally" as well, this is probably the best option for game purposes).

Finally, sorry if this was a little dense. It's a bit more work than "compile and go", but it's not really as complicated as it sounds either.  Let me know if you've any questions.
« Last Edit: April 01, 2010, 06:17:13 PM by mjau » Logged
Draknek
Level 6
*


"Alan Hazelden" for short


View Profile WWW
« Reply #4 on: April 01, 2010, 06:40:25 PM »

mjau, that looks like an incredibly useful and informative post. Thanks a lot! Gentleman

Do you have any similarly useful advice for packaging? E.g. making something like a .deb instead of a .tar.gz
Logged

JackieJay
Level 3
***



View Profile WWW
« Reply #5 on: April 01, 2010, 07:01:37 PM »

mjau: That's one epic post. Thanks a huge lot, that will be freakin useful.  Gentleman

Thanks for everyone else's replies btw !  Hand Thumbs Up LeftGrin
Logged

Average Software
Level 10
*****

Fleeing all W'rkncacnter


View Profile WWW
« Reply #6 on: April 01, 2010, 07:18:45 PM »

Quote
others have different versions of libraries in different locations, and so on.
Which is why including libraries is a good idea, similar to how you'd include .dlls in windows.

Including libraries is never a good idea.  Windows' poor library model makes this an unfortunate necessity for that OS, but it's a terrible habit.  Linux users expect to have to resolve dependencies and obtain the required libraries.

Quote
Quote
Linux releases are generally done as source, and users compile it themselves, or you find someone to make packages for various distros.
No.  Please stop saying this.  Even if he can release source, most Linux people like not having to compile everything too, and it's not an option for closed-source stuff in any case.

Linux distros are completely different operating systems.  They share a common kernel and a lot of the same software, but they all expect software to come a specific way, and barring that, they expect source.  If you make packages, you don't need to release source.

Most Linux users I deal with (myself included) prefer to build from source, and on my distro (Slackware) that's often the preferred method for installation.  We must be hanging around different Linux users.
Logged



What would John Carmack do?
BlueSweatshirt
Level 10
*****

the void


View Profile WWW
« Reply #7 on: April 01, 2010, 08:49:14 PM »

I'm thinking there's a divide of Linux users.

I think since more common people are starting to use Linux; people that came from systems like Windows or Mac(and probably still have them), that makes up one half of the divide. The other are Linux power-users who are very well educated and familiar with Linux.

I side with the less dedicated users, so I can't exactly try to lay out a competent plan of what you can do. But my general advice here, which I hope more Linuxically-educated people here can elaborate on is: Try to accommodate regular users and power users at the same time.
 Shrug
Logged

skyy
Level 2
**


[ SkyWhy ]


View Profile
« Reply #8 on: April 01, 2010, 10:21:27 PM »

Wall of awesome info.

Thank you. Any more help / links / tutorials on generally pushing out games from linux side?

I'm desperately trying to get back into the linux side development groove (been developing games and other junk on Win side for 5years now). I do my programming using command-line tools on Linux side and like to compile everything by hand to have absolute control over it but there are just generally bits here and there that my brains fart over. So the information you already gave is really helpful but if you happen to have more or any links that might just generally shed light in these kind of things on linux side, do share, because... you sir, are awesome.  My Word!

And yes, as obvious as it is, I have no specific question or "please help me with this". I just like to read stuff like that because it generally makes the whole development process more accessible and how things should be done.
Logged

Mikademus
Level 10
*****


The Magical Owl


View Profile
« Reply #9 on: April 02, 2010, 12:45:26 AM »

Most Linux users I deal with (myself included) prefer to build from source, and on my distro (Slackware) that's often the preferred method for installation.  We must be hanging around different Linux users.

Fedora user here. I am absolutely not afraid to build from source, but very much prefer pre-cooked binary packages and the automatic dependency resolution that modern package managers give. Package management is what will win people over to Linux and other open OS's, requiring or expecting building from source is something that will keep them with inferior closed ones.

Rant over. Make games, not war.
Logged

\\\"There\\\'s a tendency among the press to attribute the creation of a game to a single person,\\\" says Warren Spector, creator of Thief and Deus Ex. --IGN<br />My compilation of game engines for indies
Christian Knudsen
Level 10
*****



View Profile WWW
« Reply #10 on: April 02, 2010, 03:44:08 AM »

I currently just provide 32- and 64-bit binaries for Linux of my game. Haven't had any complaints about this. I'd like to provide packages instead, but that's something for me to learn in the future.
Logged

Laserbrain Studios
Currently working on Hidden Asset (TIGSource DevLog)
BrianSlipBit
Level 1
*



View Profile WWW
« Reply #11 on: April 02, 2010, 04:58:08 AM »

I currently just provide 32- and 64-bit binaries for Linux of my game. Haven't had any complaints about this. I'd like to provide packages instead, but that's something for me to learn in the future.

Right.  But are they prepped in a manner similar to what mjau suggests?  (Serious question BTW).  I'm just curious.
Logged

Average Software
Level 10
*****

Fleeing all W'rkncacnter


View Profile WWW
« Reply #12 on: April 02, 2010, 04:58:55 AM »

Most Linux users I deal with (myself included) prefer to build from source, and on my distro (Slackware) that's often the preferred method for installation.  We must be hanging around different Linux users.

Fedora user here. I am absolutely not afraid to build from source, but very much prefer pre-cooked binary packages and the automatic dependency resolution that modern package managers give. Package management is what will win people over to Linux and other open OS's, requiring or expecting building from source is something that will keep them with inferior closed ones.

Which is why I've mentioned packages twice already, thrice now.  Packages are the way to go, bringing over the feeble Windows (and to some extent OS X) habit of bundling libraries is not the way to go.  I mentioned source because it's the "failsafe" for distros you haven't made packages for.  Ideally, you would do both of these.

The whole point behind libraries is that multiple programs can use the same object code.  Distributing them with your program defeats that entire purpose.
Logged



What would John Carmack do?
hexageek
Level 0
***



View Profile
« Reply #13 on: April 02, 2010, 05:16:05 AM »

mjau's post makes good points but glibc doesn't always break with never versions.
I have binaries that works since ubuntu 7.04 on ubuntu and fedora machines.

also, if you use SDL and OpenGL it will even get easier since SDL is almost always backward compatible and every popular distro comes with it preinstalled.
Logged
hexageek
Level 0
***



View Profile
« Reply #14 on: April 02, 2010, 05:17:40 AM »

Most Linux users I deal with (myself included) prefer to build from source, and on my distro (Slackware) that's often the preferred method for installation.  We must be hanging around different Linux users.

Fedora user here. I am absolutely not afraid to build from source, but very much prefer pre-cooked binary packages and the automatic dependency resolution that modern package managers give. Package management is what will win people over to Linux and other open OS's, requiring or expecting building from source is something that will keep them with inferior closed ones.

Which is why I've mentioned packages twice already, thrice now.  Packages are the way to go, bringing over the feeble Windows (and to some extent OS X) habit of bundling libraries is not the way to go.  I mentioned source because it's the "failsafe" for distros you haven't made packages for.  Ideally, you would do both of these.

The whole point behind libraries is that multiple programs can use the same object code.  Distributing them with your program defeats that entire purpose.

what if the developer doesn't want to release the source and what if he wants to support fedora, opensuse, mandrake, ubuntu and debian's last 4 releases?
that makes 20 packages.
Logged
Average Software
Level 10
*****

Fleeing all W'rkncacnter


View Profile WWW
« Reply #15 on: April 02, 2010, 05:21:22 AM »

Most Linux users I deal with (myself included) prefer to build from source, and on my distro (Slackware) that's often the preferred method for installation.  We must be hanging around different Linux users.

Fedora user here. I am absolutely not afraid to build from source, but very much prefer pre-cooked binary packages and the automatic dependency resolution that modern package managers give. Package management is what will win people over to Linux and other open OS's, requiring or expecting building from source is something that will keep them with inferior closed ones.

Which is why I've mentioned packages twice already, thrice now.  Packages are the way to go, bringing over the feeble Windows (and to some extent OS X) habit of bundling libraries is not the way to go.  I mentioned source because it's the "failsafe" for distros you haven't made packages for.  Ideally, you would do both of these.

The whole point behind libraries is that multiple programs can use the same object code.  Distributing them with your program defeats that entire purpose.

what if the developer doesn't want to release the source and what if he wants to support fedora, opensuse, mandrake, ubuntu and debian's last 4 releases?
that makes 20 packages.

The right way isn't always the easy way.
Logged



What would John Carmack do?
hexageek
Level 0
***



View Profile
« Reply #16 on: April 02, 2010, 05:22:34 AM »

sometimes the easy way is the right one.
Logged
Christian Knudsen
Level 10
*****



View Profile WWW
« Reply #17 on: April 02, 2010, 05:33:05 AM »

I currently just provide 32- and 64-bit binaries for Linux of my game. Haven't had any complaints about this. I'd like to provide packages instead, but that's something for me to learn in the future.

Right.  But are they prepped in a manner similar to what mjau suggests?  (Serious question BTW).  I'm just curious.

I believe my program is only dependent on SDL and SDL_mixer (I'm programming in FreePascal, so there are probably a bunch of C libraries I don't have to worry about?). Those are included in most Linux distros, right? I distributed them with my binary at first, but people didn't like that.
Logged

Laserbrain Studios
Currently working on Hidden Asset (TIGSource DevLog)
magnum_opus
Level 1
*


View Profile
« Reply #18 on: April 02, 2010, 06:01:00 AM »

The right way isn't always the easy way.

man if you want ideological purity go use GNU HURD, Linux is all about pragmatic choices.
Logged

JackieJay
Level 3
***



View Profile WWW
« Reply #19 on: April 02, 2010, 06:33:33 AM »

As a matter of fact I'm learning SDL mainly because it's cross platforms, hence why I'm interesting in publishing my games for the Linux. For now I'll go with freeware games, but some day I might want to go commercial and I don't know if it's a good idea to distribute the source of a commercial game like that.
Logged

Pages: [1] 2
Print
Jump to:  

Theme orange-lt created by panic