[英]Program cannot find image directory when run from IDE, but CAN when run from folder?
When I build, it succeeds with no errors. 当我构建时,它成功无误。 However, when I run from the IDE, I get an error (my image fails to load because it cannot find the directory). 但是,当我从IDE运行时,出现错误(我的图像无法加载,因为找不到目录)。
However, if I go into the folder and run the program(.exe) it finds the image directory perfectly. 但是,如果我进入该文件夹并运行程序(.exe),它将找到完美的图像目录。
mTextures.Load(Textures::Background, "../GFX/Background.png");
^the line of code giving the directory. ^给出目录的代码行。
I assume this is a problem with a setting I didn't enter correctly in my compiler? 我认为这是我未在编译器中正确输入设置的问题?
I am using Code::Blocks on Windows. 我在Windows上使用Code :: Blocks。
It's because you're using a relative path in your file name: 这是因为您在文件名中使用了相对路径:
"../GFX/Background.png"
the ..
is saying "go up one directory form the current directory". ..
说“从当前目录上移一个目录”。 If you want to be able to run your program anywhere, use an absolute path, something like: 如果您希望能够在任何地方运行程序,请使用绝对路径,例如:
"/home/me/GFX/Background.png"
Your debugger's current directory (ie the current directory used when you execute the application from within codeblock) is probably incorrect. 调试器的当前目录(即,从代码块中执行应用程序时使用的当前目录)可能不正确。 Check your project settings, and fix the current directory to your target directory (the one which contains the executable itself). 检查项目设置,然后将当前目录固定到目标目录(该目录包含可执行文件本身)。
用双斜杠添加图像所在的完整路径。
mTextures.Load(Textures::Background, "C:\\Program Files\\..\\..\\GFX\\Background.png");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.