I have the following directory structure
(root)
/ | \
bin resources src
| | |
Debug dot.bmp .cpp
|
.exe
I would like the .exe file to use dot.bmp.
Here's the code from the .cpp file that loads dot.bmp
player_img = il->load_image( "dot.bmp" );
I feel like I need to modify this line of code, but after changing it to:
player_img = il->load_image( "../resources/dot.bmp" );
I still get an error saying that the image couldn't be loaded.
What do I need to change? Is this even possible, or should I just give up and put the image in the same directory as the .exe?
You need to go down one further level in order to get to the root.
Your executable is in
bin/Debugbut I think you coded under the assumption that it is inbin.Assuming you are on Windows, the relative path will be relative to the current working directory rather than the directory where the executable resides. Often they are the same thing, but not necessarily.
I would be inclined to use fully-qualified paths and pre-pend the directory where the executable lives. You can obtain this by calling
GetModuleFileNamepassingNULLas thehModuleargument. This will return the full path to the executable so you will need to strip off the file name portion.You will also need to think about deployment. This structure looks like your development structure but you may want a different organisation when you deploy the program. For example, I’d expect the executable to live in the
bindirectory when deployed.One final thought. Assuming the images that your program needs is known at compile time it would be much easier to link them into the executable as resources. That way you simply don’t have to worry about these issues at all and the executable can stand alone.