提高X上code 4库静态链接 [英] Boost library static linking on Xcode 4

查看:111
本文介绍了提高X上code 4库静态链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用利用X code在OS X Boost库。升压安装使用的MacPorts我的系统上。我已经成功地构建我的应用程序中加入我需要(例如,libboost_thread-mt.a)到目标链接二进制与图书馆列表中的3 Boost库。不过,我需要这些库静态链接,这样应用程序将在其他计算机上运行,​​而不Boost库需要被安装。

I am using the Boost library on OS X using Xcode. Boost was installed on my system using macports. I have successfully built my app by adding the 3 boost libraries I need (for example, libboost_thread-mt.a) to that Targets 'Link Binary With Libraries' list. However I need to link these libraries statically so that the app will run on other computers without the boost library needing to be installed.

我如何做到这一点是什么呢?通过我无数的谷歌搜索我发现我可能需要添加-static' - 我在哪里英寸x code添加此

How do I do this exactly? Through my numerous google searches I'm finding I might need to add '-static' - where do I add this in Xcode?

推荐答案

如果你已经有一个 .A 库链接,那么你已经静态链接。你永远需要运 .A 库。他们只是捆绑的对象。

If you've linked with a .a library, then you have already linked statically. You never need to ship .a libraries. They're just bundles of objects.

编辑:您的错误强烈建议您要链接的dylib而非.A。如果你有 libfoo.dylib的 libfoo.a中在你的库路径,即使你说链接 libfoo.a中,在X code,即使 libfoo.a中早在搜索路径,它仍将链接 libfoo.dylib的。这是因为X code'S链接是完全破碎并通过 -lfoo 来的链接(你永远不应该使用 -l <​​/ code>的东西你建立并有确切的路径)。我总是建议在xcconfig文件链接您在 LDFLAGS 建库,而不是使用构建窗格。你通过你想,而不是使用 -l <​​/ code>的确切路径。请参见放弃生成面板了解我的想法xcconfig。这是过时了,因为它是为X code3写的,但基础仍然适用。

Your error strongly suggests that you're linking the dylib rather than the .a. If you have libfoo.dylib and libfoo.a in your library path, even if you say "link libfoo.a" in Xcode, and even if libfoo.a is earlier in the search path, it will still link libfoo.dylib. This is because Xcode's linking is totally broken and passes -lfoo to the linker (you should never use -l for something you built and have the exact path to). I always recommend linking libraries you built in LDFLAGS in an xcconfig file rather than using the build pane. You pass the exact path you want rather than using -l. See Abandoning the Build Panel for more of my thoughts on xcconfig. It's out of date now, since it was written for Xcode3, but the basics still apply.

使用构建窗格中,您也可以通过整个路径到库中其他连接器选项。但是,这仍然具有构建窗格的所有问题。

Using the build pane, you can also pass the entire path to the library in "Other Linker Flags." But this still has all the problems of the build pane.

越快(但不太可靠的)解决方案,有时添加轮候册,-search_paths_first 来的其它链接器标记。使每个库路径中搜索这两个名为.dylib .A 在继续之前(默认这改变了行为行为是到处搜索名为.dylib 然后才是搜索 .A )。所以,如果你的 .A 是从不同的目录中的名为.dylib ,而目录是较早在搜索路径,这将正常工作。

The quicker (but less robust) solution is sometimes to add -Wl,-search_paths_first to the "Other Linker Flags." This changes the behavior so that each library path is searched for both .dylib and .a before going on (the default behavior is to search everywhere for .dylib and only then search for .a). So if your .a is in a different directory from your .dylib, and that directory is earlier in the search path, this will work.

这个问题终于得到了我开的这个雷达,这是我应该年前完成。我建议他人打开重复的。

This question finally got me to open a radar on this, which I should have done years ago. I recommend that others open duplicates.

这篇关于提高X上code 4库静态链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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