C ++应用程序 - 我应该使用静态或动态链接的库? [英] C++ application - should I use static or dynamic linking for the libraries?

查看:92
本文介绍了C ++应用程序 - 我应该使用静态或动态链接的库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要开始一个新的C ++项目,该项目将依托一系列库,其中包括Boost库中,log4cxx或谷歌日志库的一部分 - 而且随着项目的发展其他的也(我不能但预期)。

它必须在32位和64位系统上运行的,最有可能在一个相当多样化的Linux环境,我不希望有可用的所有需要​​的库,也不苏特权。

我的问题是,我应该动态或静态链接到这些库的建立我的应用程序?

注:

(1)我知道的静态链接可能是发展过程中的疼痛(较长的编译时间,交叉编译为32位和64位,下降依存关系链包括所有图书馆,等等),但它是一个更容易在测试过程中 - 只要将文件并运行

(2)另一方面,动态链接缝在开发阶段更容易 - 短的编译时间,(真的不知道如何从我的32位开发环境处理动态链接到64位库),具有依赖性没有喧嚣链。的另一方面新版本的部署可以是难看 - 尤其是当需要新的库(参见上述的不具有对目标机器ス权利条件,也没有这些库提供)

(3)我读过关于这个话题的相关问题,但不能真正弄清楚哪种办法最适合我的方案。

结论:


  1. 谢谢大家的意见!

  2. 我可能会使用静态链接去,因为:


    • 部署更方便

    • predictable性能和PERF期间更一致的结果。测试(看看这个文章:http://www.inf.usi.ch/faculty/hauswirth/publications/CU-CS-1042-08.pdf)

    • 正如指出的那样,规模和静态还是动态编译的时间似乎并没有成为如此巨大的差异

    • 更容易和更快的测试周期

    • 我可以把所有的开发。周期上我的开发。机



解决方案

静态链接有一个坏名声。我们有庞大的硬盘驱动器,这些天,和非凡的脂肪管道。许多旧的论点支持动态链接的方式都不太重要了。

另外,有一个很好的理由在Linux上preFER静态链接:平台配置的过多那里使它几乎不可能保证你的可执行文件将在其中的一小部分工作,没有静态链接<。 / p>

我怀疑这会不会是一个流行的观点。精细。但我有11年经验的Linux部署应用程序,并且直到像LSB真正起飞,真正扩展了它的触角,Linux将继续成为更加难以部署的应用程序。在此之前,静态链接您的应用程序,如果你要在广泛的平台上运行。

I am going to start a new C++ project that will rely on a series of libraries, including part of the Boost libraries, the log4cxx or the google logging library - and as the project evolves other ones as well (which I can not yet anticipate).

It will have to run on both 32 and 64 bit systems, most probably in a quite diverse Linux environment where I do not expect to have all the required libraries available nor su privileges.

My question is, should I build my application by dynamically or statically linking to all these libraries?

Notes:

(1) I am aware the static linking might be a pain during development (longer compile times, cross-compiling for both 32 and 64 bit, going down dependency chains to include all libraries, etc), but it's a lot easier during testing - just move the file and run.

(2) On the other hand, dynamic linking seams easier during development phase - short compile times, (don't really know how to handle dynamic linking to 64 bit libraries from my 32 bit dev environment), no hustle with dependency chains. Deployment of new versions on the other hand can be ugly - especially when new libraries are required (see condition above of not having su rights on the targeted machines, nor these libraries available).

(3) I've read the related questions regarding this topic but couldn't really figure out which approach would best fit my scenario.

Conclusions:

  1. Thank you all for your input!
  2. I will probably go with static linking because:
    • Easier deployment
    • Predictable performance and more consistent results during perf. testing (look at this paper: http://www.inf.usi.ch/faculty/hauswirth/publications/CU-CS-1042-08.pdf)
    • As pointed out, the size and duration of compilation of static vs. dynamic does not seem to be such a huge difference
    • Easier and faster test cycles
    • I can keep all the dev. cycle on my dev. machine

解决方案

Static linking has a bad rap. We have huge hard drives these days, and extraordinarily fat pipes. Many of the old arguments in favor of dynamic linking are way less important now.

Plus, there is one really good reason to prefer static linking on Linux: The plethora of platform configurations out there make it almost impossible to guarantee your executable will work across even a small fraction of them without static linking.

I suspect this will not be a popular opinion. Fine. But I have 11 years experience deploying applications on Linux, and until something like LSB really takes off and really extends it's reach, Linux will continue to be much more difficult to deploy applications on. Until then, statically link your application, if you have to run across a wide range of platforms.

这篇关于C ++应用程序 - 我应该使用静态或动态链接的库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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