简体   繁体   English

从Xcode生成的应用程序运行良好,不会直接从.app运行

[英]Application runs fine when built from Xcode, won't run directly from the .app

Working on a c++ mac application in Xcode. 在Xcode中处理c ++ mac应用程序。 When I hit run everything is fine (debug and release mode). 当我点击运行时,一切都很好(调试和发布模式)。 But when I go into finder into the Products/Release folder and double click on the .app directly, the app immediately closes with an error (application quit unexpectedly. click report to see more detailed information). 但是,当我进入finder进入Products / Release文件夹并直接双击.app时,该应用程序立即关闭并出现错误(应用程序意外退出。单击报告以查看更多详细信息)。 When I click report, the line of code it errors on seems to indicate that it isn't finding my resource files, but it finds them fine when I build/run the same exact app from xcode. 当我单击报告时,出现错误的代码行似乎表明它找不到我的资源文件,但是当我 xcode构建/运行相同的应用程序时,它发现它们很好。 heres an example of how i use the resource files in the code: 这是我如何在代码中使用资源文件的示例:

std::ifstream file;
file.open("AppName.app/Contents/Resources/Saves/1.svd");
//do stuff
file.close();

anyone have any ideas why double clicking the .app that xcode just created would have different results than running it from xcode? 有谁知道为什么双击刚创建的Xcode的.app与从xcode运行它会有不同的结果?

also not sure if this is part of the issue, but it seems strange that I have to reference the resource folder from outside the .app file (AppName.app/Contents/Resources/Saves/1.svd). 也不确定这是否是问题的一部分,但是我不得不从.app文件(AppName.app/Contents/Resources/Saves/1.svd)外部引用资源文件夹,这似乎很奇怪。 I would expect that path to be relative to the executable in .app/Contents/MacOS like this (../Resources/Saves/1.svd) but that didnt work either. 我希望该路径相对于.app / Contents / MacOS中的可执行文件是这样的(../Resources/Saves/1.svd),但也没有用。

I had similar problem and spending some time researching different options I ended up using Apple's objects. 我遇到了类似的问题,花了一些时间研究不同的选择,最终我还是使用了苹果公司的产品。 I needed to get resources folder: 我需要获取资源文件夹:

#ifdef __APPLE__
#include "CoreFoundation/CoreFoundation.h"
#endif

Then actual snippet is: 那么实际的代码片段是:

#ifdef __APPLE__

char path[FILENAME_MAX];

CFBundleRef mainBundle = CFBundleGetMainBundle();
CFURLRef resourcesURL = CFBundleCopyResourcesDirectoryURL(mainBundle);

if (!CFURLGetFileSystemRepresentation(resourcesURL, TRUE, (UInt8 *)path, PATH_MAX)){
    //
    //log("CFURLGetFileSystemRepresentation returned false. Path:%s", path);
    exit(0);
}
CFRelease(resourcesURL);

chdir(path);

//log("Current path:%s", path);
#endif

暂无
暂无

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

相关问题 CMake Big Sur 内置的 MacOS 应用程序无法在 Catalina 上运行 - CMake MacOS app built in Big Sur won't run on Catalina 如何在 Xcode 之外打开从 Xcode 构建的命令行应用程序? - How to open Command Line application built from Xcode outside of Xcode? C ++调用getenv(“ LINES”)或getenv(“ COLUMNS”)在Xcode中运行良好,在终端中运行时出现段错误 - C++ calling getenv(“LINES”) or getenv(“COLUMNS”) runs fine in Xcode, segfaults when run in terminal 从WebAPI项目运行静态类时出现StackOverflow异常-从控制台应用程序运行时运行正常 - StackOverflow exception when running static class from a WebAPI project - works fine when run from a console application Visual Studio调试器失败,但程序运行时运行良好......? - Visual Studio debugger fails but program runs fine when built…? 无法通过终端运行应用程序,但应用程序在XCode中正常运行 - Unable to Run application via Terminal but application working fine in XCode Mac os x应用程序捆绑包在下载并运行时崩溃,但在终端或更改Info.plist时运行正常 - Mac os x app bundle crashes when downloaded and run, but runs fine in the terminal or when changing Info.plist 在部署时,dev计算机上运行App将不会运行 - Running App on dev machine won't run when deployed Xcode不会检测包含文件中main中包含的文件 - Xcode won't detect files included from main in included file 多项式类在调试器中运行良好,但在尝试构建和运行时却无法运行 - Polynomial Class runs fine in debugger but not when trying to build&run
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM