基于Boost的Cocoa应用程序规模
我需要什么:
- 将基于boost的C++库包装到Objective-C++中;
- 使用 Objective-C++ 库创建 Cocoa 应用程序。
我所拥有的:
- 构建了 boost 1.46.1(动态 .dylib 和静态 .a 变体);
- C++ 库的 Xcode 项目(基于 boost,封装在 Objective-C 中);
- 最终应用程序的 Xcode 项目,其中库链接为子项目(应用程序目标依赖于库)。
我的问题:
- 当我构建应用程序时,结果二进制文件为 15~20 MB,但中间库为 100 MB。这该如何解释呢?
- 最终的应用程序(任何变体)在运行时使用系统文件夹中的 boost libs(我在“活动监视器”中的“进程信息”>“打开文件和端口”中看到这一点)。如何避免这种情况?或者如何构建完全独立、独立于库和框架的应用程序?
更多细节:
- 我尝试链接到 .dylib 和 .a 变体的库 - 中间库为 100 MB,应用程序为 15 MB;
- 我尝试使用 .framework 而不是静态库 .a — 框架为 15 MB,带有框架的应用程序为 30 MB;
- 我尝试构建纯 C++ 命令行应用程序(功能相当于 Objective-C 应用程序 + 库)——二进制大小为 15 MB;
- 库仅使用 boost 的一部分(文件系统、iostream、program_options、系统、线程)+少量系统 dylib;
- 我使用 Xcode 4.2、Mac OS X 10.6 SDK、x86_64 变体;
- 使用 LLVM GCC 4.2、Apple LLVM 3.0、GCC 4.2 编译器进行测试;
- 使用剥离调试符号是和否、死代码剥离是和否、生成调试符号是和否、优化级别-O0和-Os、隐藏内联方法是和否、默认隐藏符号是和否进行测试。
What I need:
- wrap boost-based C++ library into Objective-C++;
- create Cocoa app using that Objective-C++ library.
What I have:
- builded boost 1.46.1 (dynamic .dylib and static .a variants);
- Xcode project of C++ library (boost-based, wrapped in Objective-C);
- Xcode project of the final application with library linked as subproject (app target is dependent on library).
My questions:
- When I build application the result binary is of 15~20 MB, but intermediate library is of 100 MB. How can this be explained?
- The final application (in any variant) when ran uses boost libs from system folder (I see this in the Activity Monitor, in Process Info > Open Files and Ports). How can this be avoided? Or how to build completely standalone, libs-and-frameworks-independent application?
Some more details:
- I've tried to link to library both .dylib's and .a's variants — intermediate lib is 100 MB, app is 15 MB;
- I've tried to use .framework instead of static library .a — framework is 15 MB, app with framework is 30 MB;
- I've tried to build pure C++ commandline application (functionally equivalent to Objective-C app + library) — binary size is 15 MB;
- library uses only part of boost (filesysytem, iostream, program_options, system, threads) + few system dylibs;
- I use Xcode 4.2, Mac OS X 10.6 SDK, x86_64 variant;
- tested with LLVM GCC 4.2, Apple LLVM 3.0, GCC 4.2 compilers;
- tested with Strip Debug Symbols YES and NO, Dead Code Stripping YES and NO, Generate Debug Symbols YES and NO, Optimization Level -O0 and -Os, Inline Methods Hidden YES and NO, Symbols Hidden by Default YES and NO.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
要了解您的应用程序依赖哪些库,您可以使用
otool -L yourCocoaApp
。它将列出您的应用程序的依赖项及其完整路径。您还可以安装 captainmaclib 应用程序。要使您的应用程序使用特定版本的库,您应该调整其依赖项的路径。您可以使用 install_name_tool 命令行工具或使用上述站点中的 dylibbundler 应用程序来完成此操作。 CMake 中还包含一些工具去做它。
XCode 中可能存在工具,但我没有使用它,所以我不知道。
希望这有帮助。
to know what libraries your app depends on, you can use
otool -L yourCocoaApp
. It will list dependencies of your app and their full paths. You can also install the captainmaclib application.To make your app use specific version of a lib, you should adjust the paths of its dependencies. You can do it using the install_name_tool command line tool or using the dylibbundler app from the site above. There also is tools included in CMake to do it.
It may exists tools inside XCode but I'm not using it so I don't know.
Hope this help.