简体   繁体   English

从IDE运行时,程序找不到图像目录,但是从文件夹运行时,程序可以找到图像目录吗?

[英]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). 检查项目设置,然后将当前目录固定到目标目录(该目录包含可执行文件本身)。

Specific instructions are here . 具体说明在这里

用双斜杠添加图像所在的完整路径。

mTextures.Load(Textures::Background, "C:\\Program Files\\..\\..\\GFX\\Background.png");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在IDE外部运行时程序崩溃 - Program crashes when run outside IDE 使用sublime-build时无法运行C ++程序,从终端运行时可以正常工作 - Cannot run C++ program when using sublime-build, works fine when running from terminal VS C ++程序仅在从文件夹运行.exe时有效吗? [不是VS调试] - VS C++ program only works when .exe is run from folder? [not VS debug] 从Eclipse IDE运行可以正常运行,但是从终端运行时终止 - Run from eclipse IDE works fine but terminates when run from terminal 如何从隐藏文件夹WinAPI运行程序 - How to run program from hidden folder WinAPI 我可以在终端机上通过单击无法运行程序 - Cannot run a program by clicking on it while I can from Terminal 从 Visual Studio 运行时程序找不到相关文件 - Program doesnt find relative file when run from withing Visual Studio 尝试运行程序时出现错误的图像错误 - Bad Image error when trying to run program Directx 12说当我从书中运行演示项目时找不到它指定的路径 - Directx 12 says that it cannot find the path specified when I run a demo project from a book 当我关闭程序并在C ++中再次运行它时,如何停止记录覆盖 - How can I stop my records from overwriting when i close the program and run it again in c++
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM