Advertisement

gcc problem

Started by May 02, 2005 02:10 PM
15 comments, last by GameDev.net 19 years, 6 months ago
Hi I've written a couple of games using VC++.net and I now want to port them to Linux using gcc. There seems to be a problem. I can get the games to compile ok only there seems to be a problem with the games finding the required media file. The games work if I put the media folder in the home/ folder but not unless. Can anyone suggest why? Thanks Traiger
How are you loading the file in the code?
Advertisement
As the Limecat (:P) suggests, it is likely the way you are loading the file in your code. If you're doing something like open("data.txt"), linux is going to look for that file in your home directory as the default path. You probably have to do something like open("/.data.txt") or ./data.txt or something to tell Linux to use the current directory as the path for the file. Either ./ or /. is the root directory (you probably know) and I think the other is the current directory. Try something like that to force the path to the current directory.

Hope this helps!
Without order nothing can exist - without chaos nothing can evolve.
Thanks guys for responding.

Although I am a complete Linux novice I figured that the problem would be something to do with the path name format.

So far I have tried the following

background_img = new stDB_Images("/media/bg.bmp");

background_img = new stDB_Images("media/bg.bmp");

background_img = new stDB_Images("./media/bg.bmp");

background_img = new stDB_Images("../media/bg.bmp");

With no luck. I'll now try background_img = new stDB_Images("/.media/bg.bmp");
just for the hell of it.

Any other ideas people?

Thanks

Traiger
/. and ./ as in ./media/gfx.bmp seem to work as long as the active directory is only one level above root such as

/Pong/

if the folder was another level up it wouldn't work so /Bob/Pong wouldn't work.

Any further thoughts here?
What about the "Foo//Blah//File.fil"

Just a thought
-Frank


Advertisement
Quote: Original post by traiger
/. and ./ as in ./media/gfx.bmp seem to work as long as the active directory is only one level above root such as

/Pong/

if the folder was another level up it wouldn't work so /Bob/Pong wouldn't work.

Any further thoughts here?


Try "media/gfx.bmp"

and make sure you run the executable one level over the media directory.
Quote: Original post by traiger
background_img = new stDB_Images("/media/bg.bmp");

This looks for a file called bg.bmp in the media directory directly under the root filesystem. Most likely not what you want.

Quote:
background_img = new stDB_Images("media/bg.bmp");

This looks for bg.bmp in the media directory under the current directory (whence you ran the executable, unless it's chdir()ed to somewhere).

Quote:
background_img = new stDB_Images("./media/bg.bmp");

. is the current directory, so this will do the same as the previous one. The only reason one might write ./ explicitly is either to specify a relative path for an executable from the current directory to be run (by default only $PATH is searched), or to specify a file beginning with a dash on the command line without it being interpreted as a switch.

Quote:
background_img = new stDB_Images("../media/bg.bmp");

That looks for bg.bmp in a directory named media under the parent of the current directory (probably not what you want either, but you could).

Hope I was helpful.
Kwizatz,

Yeah thats what I started with and that wouldn't work unless the media file was in the root directory.

Devin,

Ok thanks for the break down on that lot, it's starting to look like it is getting chdir()ed somewhere.

I'm using SDL, FMOD and TTF anyone had any file handling issues with them?
I assume your application is located in a folder structure like this:

mygame+--mygame.exe+--media   +--bg.bmp


In Linux you may call getcwd to get the current working directory. This way you can check if the current working directory changed.

If your cwd is "mygame", then you can reference the file by "./media/bg.bmp". Try open the file with a call:

int fd = open("./media/bg.bmp", O_RDONLY);
if (fd == -1)
{
// error opening the file
}

then read some data:

char buffer[1024];
ssize_t size = read(fd, buffer, sizeof(buffer));
if (size == -1)
{
// reading data failed
}

and then close the file:

if (close(fd) == -1)
{
// error closing file
}

This topic is closed to new replies.

Advertisement