如何在CentOS 6上部署一个C ++ 11程序(具有依赖性),它的GCC是C ++ 03? [英] How can I deploy a C++11 program (with dependencies) on CentOS 6, whose GCC is C++03?

查看:317
本文介绍了如何在CentOS 6上部署一个C ++ 11程序(具有依赖性),它的GCC是C ++ 03?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

只要您使用相同的C ++标准, 1 ]。

GCC is great with ABI-compatibility as long as you use the same C++ standard [1].

但是它让我震惊的是,如果一个共享库编译的GCC 4.3在C ++ 03模式暴露,比如说,一个 std: :string ,这将是一个不同的 std :: string 比C ++ 11模式下由GCC 4.8编译的可执行文件所理解的。

But it strikes me that if a shared library compiled by GCC 4.3 in C++03 mode exposes, say, a std::string, this is going to be a different std::string than that understood by an executable compiled by GCC 4.8 in C++11 mode.

我问的原因是我打算在CentOS 6上部署一个由CCC11模式编译的GCC 4.8编译的程序,其最大打包GCC为4.3。 ..和一些共享库(无论是第三方C ++库还是更多的系统级东西)将推测因此都是C ++ 03。但是如果是这样,我们永远不能在旧的Linux发行版上部署任何C ++ 11程序,这似乎不太可能。

The reason I ask is that I am planning to deploy a program compiled by GCC 4.8 in C++11 mode on CentOS 6, whose maximum packaged GCC is 4.3... and some of the shared libraries (be they third-party C++ libraries or more system-level stuff) will presumably therefore all be C++03. But if that were the case, we'd never be able to deploy any C++11 programs on older Linux distributions, which seems unlikely.

这里可能有问题?

推荐答案

实际上,你可以分发一个用新的g ++编译器编译的程序在一个香草CentOS 6平台上。有几种方法可以执行此操作:最简单的方法是使用 DevToolset 3 < a>,这将给你g ++ 4.9.2(开发工具集2会给你gcc 4.8.2)。然后,使用这个g ++编译你的应用程序。当分发您的软件时,您需要确保还提供随g ++ 4.9提供的 libstdc ++。所以。可以设置 LD_LIBRARY_PATH ,使其在启动时被选中,或者设置 RPATH 告诉你的可执行文件在哪里首先查找库。

Actually, you can distribute a program compiled with a newer g++ compiler on a vanilla CentOS 6 platform. There are several ways to do this: The easiest is to use the DevToolset 3, which will give you g++ 4.9.2 (the dev toolset 2 will give you gcc 4.8.2). Then, just compile your application with this g++. When distributing your software, you need to make sure to also ship the libstdc++.so that is being shipped with g++ 4.9. Either set the LD_LIBRARY_PATH so it gets picked up on startup, or set the RPATH to tell your executable where to look first for libraries.

基本上,你也可以使用更新的编译器,但是你首先需要编译编译器本身。如果你不想首先编译一个编译器,请使用各自的开发工具集,你应该很好。

Essentially, you can do this also with newer compilers, but then you first need to compile the compiler itself. If you don't want to compile a compiler first, go with a respective dev toolset and you should be fine.

是的,你也可以尝试静态链接libstdc ++。a 。搜索选项 -static-libstdc ++

Yes, you can also try to statically link libstdc++.a. Search for the option -static-libstdc++:


使用g ++程序链接一个C ++程序,它通常自动链接到libstdc ++。如果libstdc ++可用作共享库,并且不使用-static选项,那么这将链接到共享版本的libstdc ++。这通常很好。但是,有时冻结由程序使用的libstdc ++的版本有时是有用的,而不用一直到一个完全静态的链接。 -static-libstdc ++选项指示g ++驱动程序静态链接libstdc ++,而不必静态链接其他库。

When the g++ program is used to link a C++ program, it normally automatically links against libstdc++. If libstdc++ is available as a shared library, and the -static option is not used, then this links against the shared version of libstdc++. That is normally fine. However, it is sometimes useful to freeze the version of libstdc++ used by the program without going all the way to a fully static link. The -static-libstdc++ option directs the g++ driver to link libstdc++ statically, without necessarily linking other libraries statically.

但是如果你静态链接,你不会得到任何安全更新等。授予,你不会得到更新,如果你运送libstdc ++,所以,你自己,但增量更新可能更容易。

But if you statically link, you will not get any security updates etc. Granted, you will not get the updates, if you ship libstdc++.so on your own as well, but incremental updates maybe easier.

关于运行你的应用程序:经验法则是:在你需要支持的最早的平台上编译,然后你的二进制文件(自带的libstdc ++和其他必需的libs)也可能在较新的版本上工作。也就是说,如果你在CentoOS 6上编译,并且它工作,你可以期望它也在CentOS 7上工作。在一个相关的主题,这正是为什么例如 AppImage 和相关解决方案建议使用旧系统。

And with respect to running your application: The rule of thumb is: Compile on the oldest platform you need to support, then your binaries (with self-shipped libstdc++ and other required libs) will likely work also on newer versions. That is, if you compile on CentoOS 6, and it works, then you can expect it to also work on CentOS 7. On a related subject, this is exactly the reason why for instance AppImage and related solutions recommend to build on an old system.

这篇关于如何在CentOS 6上部署一个C ++ 11程序(具有依赖性),它的GCC是C ++ 03?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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