Problem with running .exe

Hi guys

The problem I have today is probably a pretty simple one. If I open up my project in codeblocks it compiles just fine, but if I want to run it by going into the Debug-folder and then doubleclick the .exe I’m getting a blank window. The console tells me that it didn’t found the image paths which are exactly the same as in codeblocks. Do you guys have any idea what I’m doing wrong?

(I could upload some screenshots if necessary)
Sounds like an issue with the CWD ("current working directory"):


When you open files in your program, unless you provide the full, absolute path of the filename, it will be relative to the CWD.

For example:

1
2
ifstream a("c:/foo/bar.txt");  // actually opens:  C:\foo\bar.txt
ifstream b("somefile.txt");  // actually opens:  CWD\somefile.txt 


In this example, if the CWD is "C:\foo\", then you'll open "C:\foo\somefile.txt"
But if the CWD is something else, like "C:\baz\barf\", then you'll open "C:\baz\barf\somefile.txt"



Your problem is that when you run the program from the CodeBlocks, it is probably setting the CWD to something specific (like your project folder).

But when you double-click on your exe in explorer, it is setting the CWD to whatever directory your exe is in.

So your files are not where the program is looking for them.


The easiest solution here is to move the files from wherever they are not and put them in the directory that has the exe in it. Or move your exe to whatever directory has the files in it.
Thanks Disch! moving the folder with the images and sounds into the debug folder solved everything! It’s running as it’s supposed to...

Greets HalfNOoB
Topic archived. No new replies allowed.