如何在我的项目中嵌入可执行文件 [英] How to embed an executable in my project

查看:179
本文介绍了如何在我的项目中嵌入可执行文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我的Xcode / Cocoa项目中嵌入一个命令行可执行文件,然后用NSTask启动它。
我应该在setLaunchPath中使用哪个路径?

I would like to embed a command-line executable in my Xcode/Cocoa project, to then start it with NSTask. Which path should I use in the setLaunchPath ?

谢谢!

推荐答案

您应该将其添加到您的资源文件夹。
然后,在运行时,读取应用程序的资源束路径,并追加可执行文件的名称(如果您将其添加到资源束中的文件夹,则包括子文件夹)

you should add it to your resources folder. Then, in runtime, read the app's resource bundle path, and append the name of the executable (including subfolders if you add it to a folder inside the resource bundle)

例如:

NSString *execPath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"binaryname"];

NSTask *task = [[NSTask alloc] init];

[task setLaunchPath: execPath];

这篇关于如何在我的项目中嵌入可执行文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆