如何在Linux上部署C ++应用程序 [英] How to deploy C++ app on Linux

查看:732
本文介绍了如何在Linux上部署C ++应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的c ++应用程序依赖于GCC,MongoDB C ++驱动程序和Boost。我目前的做法是保持操作系统的一致性。我在Ubuntu 12.04 64位桌面上开发C ++,并将其部署到Ubuntu 12.04 64位服务器上。另外,我应该在目标服务器上安装相同版本的依赖关系。
但是如果我想在Ubuntu 13.04上开发我的C ++应用程序,并使用最新的Boost,MongoDB驱动程序和GCC 4.8.1,可以很容易地在Ubuntu 12.04服务器上部署C ++应用程序。


  1. 静态链接

  2. 动态链接,还将所有依赖关系部署到目标服务器?

    哪种方式很简单?有时,我无法在目标服务器上编译库。

    解决方案

    如果依赖关系很小,最简单的方法就是静态编译一切。在构建步骤中相当容易,并且不需要任何花哨。然而,随着更大的库和更大的项目,这可能会变得不方便。我认为最好的做法是将依赖关系编译为共享对象,然后将它们沿着二进制文件发送并执行东西以 ld 的方式第一次找你的东西。我认为这可以通过例如使用 LD_LIBRARY_PATH 例如 LD_LIBRARY_PATH = / where / did / i / ship / lib:$ LD_LIBRARY_PATH my_binary



    这可能有点麻烦,因为您需要设置您的构建系统来编译共享对象并正确打包所有内容。



    我非常确定一些为Linux发布的预编译程序以这种方式工作。奇怪的是,我目前找不到任何自定义预编译的应用程序。


    My c++ app depends on GCC, MongoDB C++ driver and Boost. My current way is to keep the OS consistent. I develop C++ on Ubuntu 12.04 64bit Desktop, and deploy it on Ubuntu 12.04 64bit server. Also I should install the same version of dependencies on target server. But If I want to develop my C++ app on Ubuntu 13.04 and use newest Boost, MongoDB driver and GCC 4.8.1, which way is easy to deploy C++ app on Ubuntu 12.04 server.

    1. static linking
    2. Dynamic linking, also deploy all dependencies to target server?

    Which way is simple? Sometimes, I cannot compile libraries on target server.

    解决方案

    If the dependencies are small easiest way is to compile everything statically. It is fairly easy during the build step, and nothing fancy is needed. However, with bigger libraries, and a bigger project this might get inconvenient.

    I think that best practice would be to compile dependencies into shared objects ship them along the binaries and execute stuff in a way that ld will look for your stuff 1st. I think it's possible by for example using LD_LIBRARY_PATH e.g. LD_LIBRARY_PATH=/where/did/i/ship/lib:$LD_LIBRARY_PATH my_binary.

    It can be somewhat cumbersome as you need to set up your build system to compile stuff as shared objects and properly pack everything.

    I'm pretty sure some of the pre-compiled programs that are shipped for linux work this way. Strangely, I can't find any custom pre-compiled app under my hand at the moment.

    这篇关于如何在Linux上部署C ++应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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