# re: traiger's gcc problem

This topic is 4822 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I know this is a bit old but I found a thread called 'gcc problem' from about a month ago, when I googled this morning. I ran into the same problem with my game. I found the solution but couldn't post it in the original thread because it had been retired. Anyway the idea is that when launching a program from a 'shortcut' in KDE or GNOME, it runs the program from the root directory with some command like '/usr/local/games/Invasion3D' and the program will fail to find your media file unless you put that media file in the /home/[user]/media directory or straight off the root (/media). So I had the same problem in my game (Invasion3D) and I fixed it with this code in the main() function: #ifdef WIN32 cTheApp.SetExePath(""); #else char chPath[256]; strcpy(chPath, argv[0]); char *pch = strrchr(chPath, '/'); if (pch) pch[1] = 0; cTheApp.SetExePath(chPath); #endif This just sets the executable path in my main game class so that when I need to load the media file I do something like this: char chMediapath[256]; strcpy(chMediapath, m_chExePath); strcat(chMediapath, "Invaders.dat"); LoadMedia(chMediapath); Hope that helps your linux port. Richard

##### Share on other sites
SirRichard

Yeah that looks good I'll give it a go. Thanks for the help.

In the end I found that the apps ran fine from the console window with ./Pong etc.

But I'll add your code with a test on argc so the app will continue to run from the console without with out requiring any arguments. I assume you do have to pass the app path in order for the code to work?

Thanks

Traiger

##### Share on other sites
Quote:
 In the end I found that the apps ran fine from the console window with ./Pong etc.

I would expect it to run fine from the console. If you have '.' in your path environment var then you don't need the './' prefix, otherwise you do. The problem that I had is getting it to run from a Gnome "shortcut".

Quote:
 But I'll add your code with a test on argc so the app will continue to run from the console without with out requiring any arguments. I assume you do have to pass the app path in order for the code to work?

You don't need to pass the path as an argument. You don't need to test argc because it's always >= 1. The first argument is _always_ the command which ran the executable, even for dos/win command line progs. In the shortcut properties, the executable path is given as '/usr/local/games/Invasion3D' so when you click on the shortcut, that will be in argv[0]. If you run from the console, argv[0] will be simply 'Invasion3D' or './Invasion3D' and in either case the code that I gave will do the right thing.

Richard

##### Share on other sites
Oops no I take that back - my original code will not properly handle the case where you run from the console without a prefix './' The correct code is like this:

#ifdef WIN32  cTheApp.SetExePath("");#else  char chPath[256];  strcpy(chPath, argv[0]);  char *pch = strrchr(chPath, '/');  if (pch)    pch[1] = 0;  else    chPath[0] = 0;  cTheApp.SetExePath(chPath);#endif

Richard

1. 1
2. 2
JoeJ
17
3. 3
4. 4
frob
11
5. 5

• 13
• 16
• 13
• 20
• 13
• ### Forum Statistics

• Total Topics
632181
• Total Posts
3004625

×