Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Run executable on Linux(Ubuntu)  (Read 4578 times)

0 Members and 1 Guest are viewing this topic.

Cranberry

  • Newbie
  • *
  • Posts: 7
    • View Profile
Run executable on Linux(Ubuntu)
« on: March 05, 2014, 05:10:49 pm »
Hey guys,
today I wrote a simple game to test sfml on Linux, but I am a real noob when it comes to developing games under Linux. (Have been using Windows before)
Whenever I start my game (not from within Codeblocks) I get an error message saying that sfml-graphics.so.2 is missing. In Windows it's simple. You just put the DLLs in the same folder as the executable, but how would I do this in Linux?
Thanks in advance,
Cranberry

Jesper Juhl

  • Hero Member
  • *****
  • Posts: 1405
    • View Profile
    • Email
Re: Run executable on Linux(Ubuntu)
« Reply #1 on: March 05, 2014, 05:26:45 pm »
If the runtime libraries are in a standard location (like /lib , /usr/lib or /usr/local/lib) the runtime linker should just find them no-problem.
If they are in a non-standard location you can edit /etc/ld.so.conf and add the path, then run ldconfig to update the locations the runtime linker searches (some distributions use a bunch of files, one for each lib, in a directory like /etc/ld.so.conf.d instead - can't remember what Ubuntu does).
You can also use the LD_LIBRARY_PATH environment variable to specify a path that should be searched.
There is also the option of using the linkers -rpath option to bake a search path into the executable.

So, there are many options each with their own pro's and con's :)

Edit: you may also want to look into the ldd tool ("man ldd").
« Last Edit: March 05, 2014, 05:42:24 pm by Jesper Juhl »

Cranberry

  • Newbie
  • *
  • Posts: 7
    • View Profile
Re: Run executable on Linux(Ubuntu)
« Reply #2 on: March 05, 2014, 05:47:33 pm »
What would be the best thing to do if I wanted to send this game to some of my friends?
I think letting them copy the libraries into the lib path wouldn't be a good idea.
Is there a way I could just send the library files with the executable and it works out of the box?
Would the option of using the linker to set the searh path be the best thing to do in this case?

Lo-X

  • Hero Member
  • *****
  • Posts: 618
    • View Profile
    • My personal website, with CV, portfolio and projects
Re: Run executable on Linux(Ubuntu)
« Reply #3 on: March 05, 2014, 06:00:44 pm »
If you want to do a copy/past plug&play version, the best is to make a 'libs' folder in your game root directory which will contain the .so files you need, and then make a small launcher script that alter the PATH and launch the game.

Something like (to test) :

#!/bin/sh

LIBS_DIR=./libs
EXECUTABLE=./my_game_exe_here

LD_LIBRARY_PATH="$LIBS_DIR":"$LD_LIBRARY_PATH" "$EXECUTABLE"

Of course make that script executable (chmod +x launcher), zip and send !

Jesper Juhl

  • Hero Member
  • *****
  • Posts: 1405
    • View Profile
    • Email
Re: Run executable on Linux(Ubuntu)
« Reply #4 on: March 05, 2014, 06:07:38 pm »
In my personal opinion these would be the preferred options (listed best first, worst last).

1. Build packages for the distribution(s) you want to target. A .deb for Ubuntu, a .rpm for RedHat etc.
If the targeted distribution already includes a use able version of SFML in their standard repository, then simply make your package depend on that so that when the user installs your application using the standard tools it will automatically pull in the distributions copy of SFML.
If the distribution does not offer a usable version of SFML then build your own SFML package for that distribution, make your application package depend on that.
Distribute your application package (+optional SFML package) via a online repository you set up that users can just add totheir distributions package manager.
Just like you'd build a .MSI package for Windows.

2. Distribute your application as a self extracting bash script that the user runs which then extracts the binary files from within itself, copies then to /opt/appname (or some user defined location) including the library files etc. Generate a "run-app" script as part of this that basically just runs your app like this:
LD_LIBRARY_PATH=/opt/appname/lib /opt/appname/bin/app

3. Provide a tar ball that just extracts everything into a "appname" directory, include a script to run the app that does
LD_LIBRARY_PATH=`pwd` ./app
Then tell users to run the app by doing
cd appname
./runapp.sh

4. Bake a path like /opt/appname/lib into the executable. Make a tar ball that extracts the libs to that path if unpacked in the root directory and your app in /opt/appname/bin .
Tell users how to extract it to correct location, then run
/opt/appname/bin/app (or add the bin path to their PATH and just run "app".

5. Some creative mix of the above or something I've not thought of.

Cranberry

  • Newbie
  • *
  • Posts: 7
    • View Profile
Re: Run executable on Linux(Ubuntu)
« Reply #5 on: March 05, 2014, 06:17:10 pm »
Thanks Lo-X!
It worked. Well kinda...
If I run the .sh script from the terminal everything works fine.
If I launch it via double-click it just loads and loads forever, but nothing happens. Do I need to set some special permissions or something? (I checked 'allow executing file as program' in the properties)

@Jesper Juhl: Thanks for your list, but I think I'll stay with this solution, because I don't want to build a package for every single change I make while being in the process of developing. I just want to send it to a friend to test the game.
« Last Edit: March 05, 2014, 06:21:12 pm by Cranberry »

Lo-X

  • Hero Member
  • *****
  • Posts: 618
    • View Profile
    • My personal website, with CV, portfolio and projects
Re: Run executable on Linux(Ubuntu)
« Reply #6 on: March 05, 2014, 10:10:31 pm »
I've to admit I never trid to double click, so I don't really know what's going on. Is the launching path wrong, I don't know :/