C++ 可执行文件无法在文件夹中运行,但可在 Mac 上从控制台运行
C++ Executable not working from folder, but working from console on Mac
我在用 C++ 和 Allegro 制作的游戏中遇到了这个奇怪的问题。
游戏的一部分使用了源文件夹中的一些图像。
我通过 gcc
编译它并创建可执行文件 main
,当我从终端调用 ./main
时它工作正常...游戏加载每个图像并且只工作很好。
但是如果我打开 finder,导航并双击同一个 main
它会崩溃,因为它无法成功从源加载图像。
如果我也尝试从 Instruments 打开它,也会发生同样的事情。
源代码文件夹结构为:
project:
| main //the executable is in the root of the project folder
| /src //Where all the cpp and h files are stored
| /obj //Where the .o files are stored
| item.png //images are also in the root of the project folder
并且图片加载功能是Allegro的基础功能
al_load_bitmap("item.png");
这是 macOS 上的预期行为。你需要一个包才能工作。它在官方 macOS 常见问题解答中:
http://liballeg.org/stabledocs/en/build/macosx.html
使用名为 fixbundle
的工具。
我在用 C++ 和 Allegro 制作的游戏中遇到了这个奇怪的问题。
游戏的一部分使用了源文件夹中的一些图像。
我通过 gcc
编译它并创建可执行文件 main
,当我从终端调用 ./main
时它工作正常...游戏加载每个图像并且只工作很好。
但是如果我打开 finder,导航并双击同一个 main
它会崩溃,因为它无法成功从源加载图像。
如果我也尝试从 Instruments 打开它,也会发生同样的事情。
源代码文件夹结构为:
project:
| main //the executable is in the root of the project folder
| /src //Where all the cpp and h files are stored
| /obj //Where the .o files are stored
| item.png //images are also in the root of the project folder
并且图片加载功能是Allegro的基础功能
al_load_bitmap("item.png");
这是 macOS 上的预期行为。你需要一个包才能工作。它在官方 macOS 常见问题解答中:
http://liballeg.org/stabledocs/en/build/macosx.html
使用名为 fixbundle
的工具。