C 可执行文件不从文件夹工作,而是在Mac上从控制台上工作

C++ Executable not working from folder, but working from console on Mac

本文关键字:工作 控制台 Mac 可执行文件 文件夹      更新时间:2023-10-16

我与Allegro一起在C 中制作的游戏有一个奇怪的问题。

游戏的一部分使用源文件夹中的一些图像。

我通过gcc编译并创建可执行文件main,当我从终端调用./main时,它可以正常工作...游戏加载每个图像并正常工作。

但是,如果我打开Finder,导航并双击相同的main,则它会崩溃,因为它无法成功地从源加载图像。如果我也尝试从乐器中打开它,也会发生同样的事情。

源代码文件夹结构是:

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

ues一种称为 fixbundle的工具。