SDL Linux Help

I’m running Kubuntu and KDevelop. I’ve had a little experience with
Linux(with cygwin and jacking numerous linux installs up). I can compile my
progs but for some reason I can’t click on the executable and run it from
folders. The only success I’ve had is from running the prog from a terminal
( ./prog ) from that directory or testing the prog from KDevelop. I think it
may be an dll/lib finding issue but since I can run them I’m not sure if
it’s an install issue or simply a linux one. I love SDL and I’ve been trying
to ease over to linux a bit since it’s cross platform.

I’m running Kubuntu and KDevelop. I’ve had a little experience with
Linux(with cygwin and jacking numerous linux installs up). I can
compile my progs but for some reason I can’t click on the executable
and run it from folders. The only success I’ve had is from running
the prog from a terminal ( ./prog ) from that directory or testing
the prog from KDevelop. I think it may be an dll/lib finding issue
but since I can run them I’m not sure if it’s an install issue or
simply a linux one. I love SDL and I’ve been trying to ease over to
linux a bit since it’s cross platform.

what application are you using to click on it ? i think that depends
on the the file browser. i can run my app in konqueror but fails since
mine needs an argument.

mattOn Tue, 17 Apr 2007 00:25:11 -0600 “Jonathan Greig” wrote:

Try running it in a terminal from a different directory and note the results.
Also note that double-click launching of a game should be done using a
.desktop file in Linux, as it makes the desktop manager’s life much
easier (see freedesktop.org for info). You can even set a command line
or current directory that way.On 4/17/07, Jonathan Greig wrote:

I’m running Kubuntu and KDevelop. I’ve had a little experience with
Linux(with cygwin and jacking numerous linux installs up). I can compile my
progs but for some reason I can’t click on the executable and run it from
folders. The only success I’ve had is from running the prog from a terminal
( ./prog ) from that directory or testing the prog from KDevelop. I think it
may be an dll/lib finding issue but since I can run them I’m not sure if
it’s an install issue or simply a linux one. I love SDL and I’ve been trying
to ease over to linux a bit since it’s cross platform.

Hello,

I am running Kubuntu too and I have no problems… I think, your problem is, that you do include some pictures or anything else. If I’m right, you should create a shellscript “start.sh” with the following lines:

#!/bin/bash

cd /where/your/prog/is
./myprog

Now type chmod +x start.sh

Then click on the script or however and it ‘should’ work…

See ya

-------- Original-Nachricht --------
Datum: Tue, 17 Apr 2007 00:25:11 -0600Von: “Jonathan Greig”
An: SDL at lists.libsdl.org
Betreff: [SDL] SDL Linux Help

I’m running Kubuntu and KDevelop. I’ve had a little experience with
Linux(with cygwin and jacking numerous linux installs up). I can compile
my
progs but for some reason I can’t click on the executable and run it from
folders. The only success I’ve had is from running the prog from a
terminal
( ./prog ) from that directory or testing the prog from KDevelop. I think
it
may be an dll/lib finding issue but since I can run them I’m not sure if
it’s an install issue or simply a linux one. I love SDL and I’ve been
trying
to ease over to linux a bit since it’s cross platform.


“Feel free” - 10 GB Mailbox, 100 FreeSMS/Monat …
Jetzt GMX TopMail testen: http://www.gmx.net/de/go/topmail

Hi,

Since when does a Unix application (C/C++ one) need a shell
script to start from the desktop?

That looks like you might have some path problems with your
libraries. Or validate that the x bit is set.

Cheers,
Paulo

Quoting Philipp Lorenz :> Hello,

I am running Kubuntu too and I have no problems… I think, your problem is,
that you do include some pictures or anything else. If I’m right, you should
create a shellscript “start.sh” with the following lines:

#!/bin/bash

cd /where/your/prog/is
./myprog

Now type chmod +x start.sh

Then click on the script or however and it ‘should’ work…

See ya

-------- Original-Nachricht --------
Datum: Tue, 17 Apr 2007 00:25:11 -0600
Von: “Jonathan Greig”
An: SDL at lists.libsdl.org
Betreff: [SDL] SDL Linux Help

I’m running Kubuntu and KDevelop. I’ve had a little experience with
Linux(with cygwin and jacking numerous linux installs up). I can compile
my
progs but for some reason I can’t click on the executable and run it from
folders. The only success I’ve had is from running the prog from a
terminal
( ./prog ) from that directory or testing the prog from KDevelop. I think
it
may be an dll/lib finding issue but since I can run them I’m not sure if
it’s an install issue or simply a linux one. I love SDL and I’ve been
trying
to ease over to linux a bit since it’s cross platform.


“Feel free” - 10 GB Mailbox, 100 FreeSMS/Monat …
Jetzt GMX TopMail testen: http://www.gmx.net/de/go/topmail


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


This message was sent using IMP, the Internet Messaging Program.

Hi,

Since when does a Unix application (C/C++ one) need a shell
script to start from the desktop?

openoffice on gentoo uses a perl script as a wrapper. i have redhat
but not booted to that at the moment to check.

mattOn Tue, 17 Apr 2007 12:33:07 +0100 Paulo Pinto wrote:

Here is what happens in the konsole:

jpg at kubuntu-computer:~/hellosdl/debug/src$ ./hellosdl
TESTING: _
jpg at kubuntu-computer:~/hellosdl/debug/src$ cd …
jpg at kubuntu-computer:~/hellosdl/debug$ src/./hellosdl
Segmentation fault
jpg at kubuntu-computer:~/hellosdl/debug$

It wont run from any directory other than it’s own. I’ve had problems
with segfaults on windows but usually those were caused by a missing
graphic. I know thats not the case here though. My prog is loading one
bitmap and it is there.

I made a helloworld prog and I could run helloworld fine from any
directory as well as the “Run Command” menu.On 4/17/07, matt wrote:

On Tue, 17 Apr 2007 12:33:07 +0100 Paulo Pinto wrote:

Hi,

Since when does a Unix application (C/C++ one) need a shell
script to start from the desktop?

openoffice on gentoo uses a perl script as a wrapper. i have redhat
but not booted to that at the moment to check.

matt


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

Probaly your code are access protected memory address.

Example:

char x[50];
printf("%c", x[60]);

At windows it works. At linux, it result in a Segmentation fault.

Maybe the problem is other, but ever i have Segmentation fault was this problem.

Regards,

R?benOn 4/17/07, Jonathan Greig wrote:

Here is what happens in the konsole:

jpg at kubuntu-computer:~/hellosdl/debug/src$ ./hellosdl
TESTING: _
jpg at kubuntu-computer:~/hellosdl/debug/src$ cd …
jpg at kubuntu-computer:~/hellosdl/debug$ src/./hellosdl
Segmentation fault
jpg at kubuntu-computer:~/hellosdl/debug$

It wont run from any directory other than it’s own. I’ve had problems
with segfaults on windows but usually those were caused by a missing
graphic. I know thats not the case here though. My prog is loading one
bitmap and it is there.

I made a helloworld prog and I could run helloworld fine from any
directory as well as the “Run Command” menu.

On 4/17/07, matt wrote:

On Tue, 17 Apr 2007 12:33:07 +0100 Paulo Pinto wrote:

Hi,

Since when does a Unix application (C/C++ one) need a shell
script to start from the desktop?

openoffice on gentoo uses a perl script as a wrapper. i have redhat
but not booted to that at the moment to check.

matt


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


R?ben L?cio Reis

Linux Game Developer
Linux user #433535

Interesting,
When I copy the graphic to the src folder, I can run my prog from the
terminal by typing

src/./hellosdl

from the src directory, but I still cant double click it and run my
prog from konqueror.

I downloaded krusader and it ran the prog just fine. I also downloaded
Dolphin and it didn’t work either. Is there some setting in konqueror
that I have to update the search path to the directory that the prog
is in(like on the fly) such as i.e. $PATH=PATH
DirectoryOfTheProgramIWantToRun ?

Here is what happens in the konsole:

jpg at kubuntu-computer:~/hellosdl/debug/src$ ./hellosdl
TESTING: _
jpg at kubuntu-computer:~/hellosdl/debug/src$ cd …
jpg at kubuntu-computer:~/hellosdl/debug$ src/./hellosdl
Segmentation fault
jpg at kubuntu-computer:~/hellosdl/debug$

It wont run from any directory other than it’s own. I’ve had problems
with segfaults on windows but usually those were caused by a missing
graphic. I know thats not the case here though. My prog is loading one
bitmap and it is there.

I made a helloworld prog and I could run helloworld fine from any
directory as well as the “Run Command” menu.

jpg at kubuntu-computer:~/hellosdl/debug$ src/./hellosdl

is the same as

jpg at kubuntu-computer:~/hellosdl/debug$ src/hellosdl

the single dot is the currect dir. ( i think its the same on windows)
the dot is needed to tell the the shell where to start looking for the
binary to run.

i am kinda thinking that you are attempting to open a file in the
current dir and assuming it works. do you have runtime checks for
that ?

SDL_Surface *my_surface;

my_surface = SDL_LoadBMP(my_filename);

if(my_surface == NULL)
{
fprintf(stderr, “error, failed to open image !!”);
exit(1);
}

not sure how you can open an image from the any path. if you are using
a file browswer, it might not have a path set, so it can not find the
image. i dont know how to get that at runtime either that would be
platform independent. you might need to have a variable that hard
codes it, but that is not the best solution.

mattOn Tue, 17 Apr 2007 17:58:00 -0500 “Jonathan Greig” wrote:

The most cross-platform way to do that is to grab the path from
argv[0]. There are a number of other ways (ie I’m using NSBundle with
Cocoa OS X/Cocotron Win32 to find things in
my.app/Contents/Resources).On 4/18/07, matt wrote:

not sure how you can open an image from the any path.

  • ?

Hi,

just use getcwd() to get the current path.

Cheers,
Paulo

Quoting matt :> On Tue, 17 Apr 2007 17:58:00 -0500 “Jonathan Greig” wrote:

Here is what happens in the konsole:

jpg at kubuntu-computer:~/hellosdl/debug/src$ ./hellosdl
TESTING: _
jpg at kubuntu-computer:~/hellosdl/debug/src$ cd …
jpg at kubuntu-computer:~/hellosdl/debug$ src/./hellosdl
Segmentation fault
jpg at kubuntu-computer:~/hellosdl/debug$

It wont run from any directory other than it’s own. I’ve had problems
with segfaults on windows but usually those were caused by a missing
graphic. I know thats not the case here though. My prog is loading one
bitmap and it is there.

I made a helloworld prog and I could run helloworld fine from any
directory as well as the “Run Command” menu.

jpg at kubuntu-computer:~/hellosdl/debug$ src/./hellosdl

is the same as

jpg at kubuntu-computer:~/hellosdl/debug$ src/hellosdl

the single dot is the currect dir. ( i think its the same on windows)
the dot is needed to tell the the shell where to start looking for the
binary to run.

i am kinda thinking that you are attempting to open a file in the
current dir and assuming it works. do you have runtime checks for
that ?

SDL_Surface *my_surface;

my_surface = SDL_LoadBMP(my_filename);

if(my_surface == NULL)
{
fprintf(stderr, “error, failed to open image !!”);
exit(1);
}

not sure how you can open an image from the any path. if you are using
a file browswer, it might not have a path set, so it can not find the
image. i dont know how to get that at runtime either that would be
platform independent. you might need to have a variable that hard
codes it, but that is not the best solution.

matt


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


This message was sent using IMP, the Internet Messaging Program.

It won’t work, as it will fail the same way it does currently (if the
BMP he’s trying to load is not in the current directory, it’ll fail to
load).
dirname(argv[0]) is usually the way to go (this does not remove load
checks as argv[0] can be modified, but one can count on the fact that
barring bizarre exec()s it’ll be correct for users launching the app
in usual ways).

  • ?On 4/18/07, Paulo Pinto wrote:

Hi,

just use getcwd() to get the current path.

millenomi wrote:

It won’t work, as it will fail the same way it does currently (if the
BMP he’s trying to load is not in the current directory, it’ll fail to
load).
dirname(argv[0]) is usually the way to go (this does not remove load
checks as argv[0] can be modified, but one can count on the fact that
barring bizarre exec()s it’ll be correct for users launching the app
in usual ways).

This problem that seems so “easy” to solve has not a clean solution on
unix systems, you have no way to know the exact path where your
executable lives when your program is launched in different ways (from
desktop, from shell, from a script through an absolute path…)

The guys of autopackage have built a small utility to solve this,
BINRELOC, but it’s targeted only at linux (I think it doesn’t work for
instance on bsd systems).

Many apps choose to start with a script created in the installation
procedure (this is the case of most apps that use loki installer for
instance), also mozilla/firefox/thunderbird “executables” are really a
script!

So I suggest you to do one of the following things:

  1. Insert binreloc in your code
  2. Build a wrapper script in the install stage and a .desktop file for
    kde/gnome
  3. Hardcode the absolute paths of the datafiles (the usual way of unix
    projects based on autoconf/automake)
  4. Write some code to encode the bmp on your binary and read them
    through SDL_rwops

I’ve used 1, 2 and 4 in different projects :)—
Bye,
Gabry

Whoo, I can’t believe no-one’s answered this correctly yet.

You’re using relative paths which rely on the current working directory
(CWD) being the one the program is run from but when you click on a
binary in konqueror the CWD is always your home directory. Best way to
get around this for the time being is to create a shortcut next to it
and specify the CWD in Work Directory.

Right click on the background of the folder and choose create new >>
link to application.

Name it under the General tab, go to the Application tab and:

  • name it again
  • put the full execution path and executable name in the Command field
  • put the full path of the directory it lives in, in Work Path

Select OK and run it through this shortcut from now on.On Wed, 2007-04-18 at 09:27 +0200, millenomi wrote:

On 4/18/07, Paulo Pinto wrote:

Hi,

just use getcwd() to get the current path.

It won’t work, as it will fail the same way it does currently (if the
BMP he’s trying to load is not in the current directory, it’ll fail to
load).
dirname(argv[0]) is usually the way to go (this does not remove load
checks as argv[0] can be modified, but one can count on the fact that
barring bizarre exec()s it’ll be correct for users launching the app
in usual ways).


All new Yahoo! Mail “The new Interface is stunning in its simplicity and ease of use.” - PC Magazine
http://uk.docs.yahoo.com/nowyoucan.html

Paul: this creates a .desktop file, which was mentioned in the thread.
This also creates a dependency on the particular .desktop file (which
might be fine, but then it might not be, depending on the situation).On 4/26/07, Paul Duffy wrote:

Whoo, I can’t believe no-one’s answered this correctly yet.

  • ?

True, but it didn’t explain how or why. There is another method whereby
you can get the PID, dereference the symlink for /proc/PID/exe, slice
off everything after the last / and change the CWD to this, but it’s
generally frowned upon for security reasons.On Thu, 2007-04-26 at 18:16 +0200, millenomi wrote:

On 4/26/07, Paul Duffy <@Paul_Duffy> wrote:

Whoo, I can’t believe no-one’s answered this correctly yet.

Paul: this creates a .desktop file, which was mentioned in the thread.
This also creates a dependency on the particular .desktop file (which
might be fine, but then it might not be, depending on the situation).


Inbox full of spam? Get leading spam protection and 1GB storage with All New Yahoo! Mail. http://uk.docs.yahoo.com/nowyoucan.html

I agree with this, and I’ll add my 2cents to help clarify the situation.

The segfault is probably done because something wrong happened, and no
check is done so the program moves deeper into the mess until it gets
segfault.

Having a printf() before and after every commands will highlight well
what is causing issues.

It has been pointed out that it could be a problem with the path.
The problem might be because your code has relative paths like
"myimg.jpg" or “data/myimg.jpg”. Compared to a absolute path like
"/path/to/myimg.jpg".

A program that is made with absolute path will never have a problem
(will not require any scripts or .desktops) but will require to be
installed correctly (say, in the same path all the time).

Using relative path becomes a bit more tricky, as you either need to
start the program at that path (’./prog’) or use some magic… here
you can set the correct path, then start the program using a script,
you can start the program with a ‘root’ argument that tell the prog
where it can find its images (’/path/to/prog --rootdir
/path/to/images’).

With relative, keep in mind that in some way, the program has to know
where the files it needs are. With absolute, it knows where the
files are, but they better be there!

HTH,
SimonOn 4/26/07, millenomi wrote:

On 4/26/07, Paul Duffy wrote:

Whoo, I can’t believe no-one’s answered this correctly yet.

Paul: this creates a .desktop file, which was mentioned in the thread.
This also creates a dependency on the particular .desktop file (which
might be fine, but then it might not be, depending on the situation).

  • ?

SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

A program that is made with absolute path will never have a problem
(will not require any scripts or .desktops) but will require to be
installed correctly (say, in the same path all the time).

not really. it needs a configure script that can handle --bindir=DIR
and --datadir=DIR so it may be installed to /usr/bin/ or /usr/local/bin/

mattOn Thu, 26 Apr 2007 13:03:10 -0500 Simon <simon.xhz at gmail.com> wrote:

Simon-
Okay, I AM relying on relative paths. I use Windows and Dos alot so I
know the differences calling progs between them. It appears that in Linux,
that most programs come with a configure script and then you make, make &&
install them from terminal/console. Well this installs them to a directory
similar to “Program Files” in windows would. All of my development in
windows uses relative paths. In windows, you can be in the browser(Windows
Explorer) and double click the executable and it will start fine regardless
of if you are in the “absolute path” or if you copied the folder to
somewhere else on your harddrive and double clicked on it. Essentially, what
I want to do is be able to double click on my program and it will run.
Obviously, konqueror must run the prog but the search path is only in the
system files directories or the root dir…

I want my code to be able to run regardless of if it’s being clicked on in
Konqueror, Krusader, or some other file manager/browser. Likewise, if I give
my prog to Joe Shmoe my neighbor, or someone else that he will be able to
run it.

I’ve seen the notation you used before, but as file or something
similar. When compiling progs for linux, should I always include where
or something in my paths in my code?

Matt-
…or do I have to ALWAYS install my progs to test them as if I was a
beta-tester? For example…

In windows, I use ResHack alot. It’s a resource editor. The exe comes in a
.zip file that you can extract anywhere to your harddrive. Regardless of
where I extract it(be it “Program Files” directory or "My SDL Progs"
directory), it just works. Why does it work, well thats because somehow in
the background the DOS PATH= has been set by windows before it executes.

Paul-
I’ll try that for the time being.
Are you telling me that in Konqueror, that it’s not possible?..such as
it cannot start the program from the CWD?
Specify the CWD in the Work directory? What? Sorry, but please explain
this a little better. How would that help me when double clicking on the
executable?

Anyone-
If it would help, could you supply some snipplets of code as to how this
would work?