使用不同目录中的映像执行的文件
Executable using images in different directory
我有以下目录结构
(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.
../../resources/dot.bmp
您的可执行文件在bin/Debug
中,但我认为您是在假设它在bin
中的情况下进行编码的。
假设您在Windows上,相对路径将相对于当前工作目录,而不是可执行文件所在的目录。它们通常是相同的东西,但不一定。
我倾向于使用完全限定的路径,并预先挂起可执行文件所在的目录。您可以通过调用GetModuleFileName
并将NULL
作为hModule
参数来获得此值。这将返回可执行文件的完整路径,因此您需要去掉文件名部分。
您还需要考虑部署。这个结构看起来像你的开发结构,但当你部署程序时,你可能想要一个不同的组织。例如,我希望可执行文件在部署时位于bin
目录中。
最后一个想法。假设您的程序需要的映像在编译时是已知的,那么将它们作为资源链接到可执行文件中会容易得多。这样一来,您根本不必担心这些问题,并且可执行文件可以独立运行。
- SDL 映像:无法打开映像,仅显示错误消息
- C++ W:使用子线程的运行映像
- 从头开始为应用程序创建 docker 映像是否有意义?
- 主机箱/bash 未执行 docker 映像
- 无法从Java读取C++中保存的Opencv Mat映像
- CMake链接库在Docker映像中失败
- 在.NET Core 3.1中运行托管C++/CLI程序集时,映像格式错误
- 如何在C++中使用ZeroMQ通信多个映像
- 无法写入映像 SimpleElastix (Python)
- 如何在 windowsservercore Docker 映像上安装执行本机C++ DLL/EXE 所需的所有依赖二进制
- 无法将映像加载到 SDL2 程序
- 从 docker 映像构建中省略安装文件
- 使用 OpenGL 中的 imageStore 写入映像
- QML 映像不会在映像源中加载具有非 ASCII 字符的图像
- 警告在将 OpenCV 垫映像投射到 QImage 时使用旧式转换
- 在控制台上显示 BMP 映像时堆损坏
- 处理映像上的多个转换
- 我可以将带有依赖项的C++库作为 Docker 映像分发吗?
- 如何使用"trusty"映像在本地执行C++程序的Travis CI?
- 使用不同目录中的映像执行的文件