我正在尝试将我的二进制文件打包到一个简约的应用程序包中。但是我看到了一些奇怪的结果。
我的 bundle 具有以下最小结构:
$ ls -R HelloWorld.app
Contents
HelloWorld.app/Contents:
Info.plist MacOS PkgInfo
HelloWorld.app/Contents/MacOS:
helloworld
helloworld是从以下语言编译的C二进制文件:
#include <stdio.h>
#include <unistd.h>
int main(int argc, char **argv) {
while (1) {
printf("Hello world!\n");
sleep(2);
}
return 0;
}
Info.plist包含:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleExecutable</key>
<string>helloworld</string>
<key>CFBundleIdentifier</key>
<string>com.litl.helloworld</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>HelloWorld</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>1.0.0</string>
<key>CFBundleVersion</key>
<string>20</string>
<key>LSMinimumSystemVersion</key>
<string>10.6</string>
<key>LSUIElement</key>
<true/>
<key>LSBackgroundOnly</key>
<true/>
</dict>
</plist>
现在为奇怪的行为。当我运行时
open ./HelloWorld.app
该命令挂起大约30秒。之后,我可以确认helloworld二进制文件正在运行。但是,其标准输出不会显示在Console.app中。如果我以编程方式启动此 bundle 软件(NSWorkspace sharedWorkspace)launchApplicationAtURL ...),则调用成功,但是二进制文件立即退出(我可以在控制台中看到它以错误代码2退出)。
这是在OS X 10.9.2上。
我究竟做错了什么?
最佳答案
您需要向Cocoa注册,以将您的应用程序标记为响应式且“就绪”。如果您启用了停靠图标,则意味着它会停止弹跳。就您而言,如果您从扩展坞中隐藏图标,则仍然需要向Cocoa注册。
您可以这样做,例如通过创建NSApplication
类。有关一些低级详细信息,请参见here。
关于macos - 在Mac OS X应用程序 bundle 中打包C二进制文件,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/22645415/