简体   繁体   English

在转换到C ++ 11期间管理外部库(例如boost)

[英]Managing external libraries (e.g. boost) during transition to C++11

I want to move my current project to C++11. 我想将我当前的项目移动到C ++ 11。 The code all compiles using clang++ -std=c++0x. 代码全部使用clang ++ -std = c ++ 0x编译。 That is the easy part :-) . 这是容易的部分:-)。 The difficult part is dealing with external libraries. 困难的部分是处理外部图书馆。 One cannot rely on linking one's C++11 objects with external libraries that were not compiled with c++11 (see http://gcc.gnu.org/wiki/Cxx11AbiCompatibility ). 人们不能依赖于将一个C ++ 11对象与未使用c ++ 11编译的外部库相链接(请参阅http://gcc.gnu.org/wiki/Cxx11AbiCompatibility )。 Boost, for example, certainly needs re-building ( Why can't clang with libc++ in c++0x mode link this boost::program_options example? ). 例如,Boost肯定需要重新构建( 为什么不能用c ++ 0x模式中的libc ++来链接这个boost :: program_options示例? )。 I have source for all of the external libraries I use, so I can (with some pain) theoretically re-build these libs with C++11. 我有我使用的所有外部库的源代码,所以我可以(有些痛苦)从理论上用C ++ 11重新构建这些库。 However, that still leaves me with some problems: 但是,这仍然存在一些问题:

Developing in a mixed C++03/C++11 environment: I have some old projects using C++03 that require occasional maintenance. 在混合C ++ 03 / C ++ 11环境中开发:我有一些使用C ++ 03的旧项目,需要偶尔进行维护。 Of course, I'll want to link these with existing versions of external libraries. 当然,我想将这些与现有版本的外部库链接起来。 But for my current (and new) projects, I want to link with my re-built C++11 versions of the libraries. 但是对于我当前(和新)的项目,我想链接到我重新构建的C ++ 11版本的库。 How do I organise my development environments (currently Ubuntu 12.04 and Mac OS X 10.7) to cope with this? 如何组织我的开发环境(目前是Ubuntu 12.04和Mac OS X 10.7)来应对这种情况?

I'm assuming that this problem will be faced by many developers. 我假设很多开发人员都会遇到这个问题。 It's not going to go away, but I haven't found a recommended and generally approved solution. 它不会消失,但我没有找到推荐的,普遍认可的解决方案。

Deployment: Currently, I deploy to Ubuntu 12.04 LTS servers in the cloud. 部署:目前,我部署到云中的Ubuntu 12.04 LTS服务器。 Experience leads one to depend (where possible) on the standard packages (eg libboost) available with the linux distribution. 经验导致一个人(在可能的情况下)依赖于Linux发行版提供的标准包(例如libboost)。 If I move my current project to c++11, my understanding is that I will have to build my own versions of the external libraries I use. 如果我将当前项目移动到c ++ 11,我的理解是我将不得不构建自己的外部库版本。 My guess is that at some point this will change, and their will be 'standard' versions of library packages with C++11 compatibility. 我的猜测是,在某些时候这将改变,并且它们将是具有C ++ 11兼容性的库标准的“标准”版本。 Does anyone have any idea when one might expect that to happen? 当有人预料到会发生这种情况时,有谁有任何想法? And presumably this will also require a standard solution to the problem mentioned above - concurrent existence of C++03 libs and C++11 libs on the same platform. 并且可能这也需要上述问题的标准解决方案 - 在同一平台上同时存在C ++ 03库和C ++ 11库。

I am hoping that I've missed something basic so that these perceived problems disappear in a puff of appropriate information! 我希望我错过了一些基本的东西,以便这些感知的问题在适当的信息中消失! Am I trying to move to C++11 too soon? 我是否想过早地转向C ++ 11?

Update(2013-09-11): Related discussion for macports: https://lists.macosforge.org/pipermail/macports-users/2013-September/033383.html 更新(2013-09-11):macports的相关讨论: https ://lists.macosforge.org/pipermail/macports-users/2013-September/033383.html

You should use your configure toolchain (eg autotools) to "properly" configure your build for your target deployment. 您应该使用配置工具链(例如autotools)“正确”配置目标部署的构建。 Your configuration tests should check for ABI compatible C++11 binaries and instruct the linker to use them first if detected. 您的配置测试应检查ABI兼容的C ++ 11二进制文件,并指示链接器在检测到时首先使用它们。 If not, optionally fail or fallback to a C++03 build. 如果没有, 可选择失败或回退到C ++ 03版本。

As for C++11 3rd part libraries installed in a separate parallel directory tree, this isn't strictly necessary. 对于安装在单独的并行目录树中的C ++ 11第三方库,这不是绝对必要的。 Library versioning has been around for a long time and allows you to place different versions side by side on the system or wherever you'd like, again based on configure. 库版本已经存在了很长时间,并且允许您在系统或任何您喜欢的位置并排放置不同版本,同样基于configure。

This might seem messy, but configure toolchains were designed to handle these messes. 这可能看起来很乱,但配置工具链是为处理这些混乱而设计的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM