【问题标题】:C++ Executable not working from folder, but working from console on MacC++ 可执行文件不能从文件夹工作,但可以从 Mac 上的控制台工作
【发布时间】:2017-10-05 09:41:48
【问题描述】:

我用 Allegro 用 c++ 制作的游戏遇到了这个奇怪的问题。

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

我通过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");

【问题讨论】:

    标签: c++ gcc allegro allegro5


    【解决方案1】:

    这是 macOS 上的预期行为。你需要一个捆绑包才能工作。它在官方 macOS 常见问题解答中:

    http://liballeg.org/stabledocs/en/build/macosx.html

    使用名为 fixbundle 的工具。

    【讨论】:

    • 嗯...显然通过自制软件安装 allegro 并没有安装所有内容,我错过了 fixbundle 命令...我将尝试重建 allegro 源并希望最好。
    • 我构建了 allegro 源代码,即使最后使用了“make install”,但仍然没有 fixbundle 命令...有什么建议吗?
    • 好的,我设法在我的 makefile 中实现了一个“捆绑制作”,所以现在当我制作它时,它会自动制作 .app 文件,其中包含所有必要的东西以使其正常工作。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-06-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-08-10
    • 2018-05-04
    • 1970-01-01
    相关资源
    最近更新 更多