[转]New Features of C++0x

本文介绍了C++0x标准中预期包含的主要新特性,包括概念、垃圾收集、并发内存模型及并发库等,并指出模块和动态库等特性由于需要更多工作而暂未纳入。

What's in C++0x

You can get a very good feel for the contents of C++0x by looking at the first partial draft mentioned above. That draft contains the bulk of the extensions the committee pulled in from the first C++ Standard Library Extensions Technical Report (TR1). It does not, however, contain text for all major features yet, and has placeholders for the major features that I'll summarize in this section.

Barring a disaster, here are the following additional major features not yet in the above partial draft that will be in C++0x. Every bullet heading links to a good "read this first" paper about the feature, and for some I've included additional links.

Concepts [N2081]

From that paper:

"Concepts introduce a type system for templates that makes templates easier to use and easier to write. By checking the requirements that templates place on their parameters prior to template instantiation, concepts can eliminate the spectacularly poor error messages produced by today’s template libraries, making them easier to use. ... At the core of concepts is the idea of separate type checking for templates. Template declarations are augmented with a set of constraints (requirements): if the definition of the template typechecks against these requirements, and a use of a template meets these requirements, then the template should not fail to instantiate."

Imagine, if you will, an error message like 'sorry, YourType isn't a BidirectionalIterator' instead of three pages of arcane messages about what templates couldn't be instantiated. Among other things, concepts will let us write the standard's own container and iterator requirements in code, rather than as English "cookbooks" of programming conventions.

The concepts proposal is coauthored by Bjarne Stroustrup and Doug Gregor. You can already start trying them out: There is a ConceptGCC proof-of-concept implementation that covers most of the proposal. For more details about how concepts can be applied to the C++ standard library, see also papers N2082, N2083, N2084, and N2085.

Garbage collection [N2129]

A C++0x compiler must provide garbage collection, which the programmer can use on request; "don't GC this region of code" is still the default. This "opt-in" model leaves existing programs' semantics unchanged, while providing real GC support for programs that want it. It is also intended to enable garbage collection for objects allocated and manipulated by most legacy libraries, which both makes it much easier to convert existing code to a garbage-collected environment and helps "repair" legacy code with deficient memory management. Of course, any C++98/03/0x compiler is already free to garbage-collect the whole C++ heap, and a number of current implementations do that; but they aren't required to do so, and this change would require GC to be available in a way that programmers can use and rely on. This work has been primarily driven by Hans Boehm and Mike Spertus. You can find a detailed paper here: N2128.

Memory model for concurrency [N2138]

As I wrote in "The Free Lunch Is Over", chip designers and compiler writers "are under so much pressure to deliver ever-faster CPUs that they’ll risk changing the meaning of your program, and possibly break it, in order to make it run faster." This only gets worse in the presence of multiple cores and processors.

A memory model is probably of the lowest-level treaty between programmers and would-be optimizers, and fundamental for any higher-level concurrency work. Quoting from my memory model paper: "A memory model describes (a) how memory reads and writes may be executed by a processor relative to their program order, and (b) how writes by one processor may become visible to other processors. Both aspects affect the valid optimizations that can be performed by compilers, physical processors, and caches, and therefore a key role of the memory model is to define the tradeoff between programmability (stronger guarantees for programmers) and performance (greater flexibility for reordering program memory operations)." This work is being driven primary by Hans Boehm, Clark Nelson, and myself.

Concurrency libraries [N2094]

The committee will likely release the concurrency libraries in two parts, both of which are likely to be released at about the same time.

  • In C++0x itself: Support at the level of basic threads and locks, as well as atomic operations for lock-free coding, and related features like thread local storage.
  • In the second C++ Standard Library Extensions Technical Report (aka Library TR2): More advanced extensions including futures and upgradable locks, so that we can gain experience with them before considering them for the standard itself post-C++0x. This follows the same path the committee took with the first set of library extensions, including shard_ptr and the hash-based containers: Those were first put into a separate TR (TR1), completed in 2004, and then based on experience most TR1 features were voted into the standard itself in April 2006 so that they are now part of the current partial draft of C++0x. The TR2 features are planned to be on a similar path, but for now are being released as a separate specification and not part of C++0x.

For more information and snapshots of current draft proposals still under discussion and development, see: N1907, N1966N2047, and N2090.

What's not in C++0x

The following major features were cut from C++0x because they require more work and would delay the next standard. Once C++0x is done, the committee may pick them up again.

Modules [N2073]

It's definitely desirable to have a module system for C++ to package libraries and their implementations, and to provide an alternative to C++'s current build model based on textual source file inclusion. Reliance the current source file inclusion model poses technical difficulties for large C++ programs, notably: (a) long build times for large projects; and (b) difficulty of managing dependencies between interfaces and implementations. The current work has been spearheaded primarily by Daveed Vandevoorde (of EDG fame). The committee still intends to do work on this, but it's now planned as a separate Technical Report on Modules after C++0x is complete rather than as part of the C++ standard.

Dynamic libraries [N1496]

Although C++ programmers routinely use shared libraries in C++ today, the C++ standard doesn't specify their semantics in a portable way. Indeed, there are some fundamental semantic differences between some popular approaches, such as between Windows static and dynamic libraries and Linux shared libraries. Note that C++'s broad cross-platform support, and the existence of many existing approaches on those different platforms, makes it more difficult to specify portable library semantics than in languages like Java that started fresh with their own (then-new) run-time environment. Several committee members, notably Pete Becker, have done work to try to reconcile the existing approaches in a standard way that implementers could broadly support, but this effort will not be ready in time for C++0x.

 

Originally posted in Herb Sutters blog:http://herbsutter.spaces.live.com/blog/cns!2D4327CC297151BB!159.entry

<think> 我们正在处理ORB_SLAM2构建过程中的几个问题: 1. CMake兼容性警告(CMake < 2.8.12)和策略CMP0022警告。 2. OpenCV版本未找到(要求OpenCV>2.4.3,但实际可能使用的是OpenCV4.4)。 3. 配置失败导致makefile缺失,进而无法构建。 根据引用内容,我们需要修改CMakeLists.txt文件,特别是: - 更新`cmake_minimum_required`版本以避免兼容性警告。 - 设置策略CMP0022为NEW以避免策略警告。 - 调整OpenCV的查找逻辑,使其能够找到OpenCV4.4(如引用[2]所示)。 - 另外,引用[3]提到删除编译选项`-march=native`来解决某些编译错误(但这不是当前的主要问题,我们先解决主要问题)。 步骤: ### 1. 解决CMake兼容性警告 在ORB_SLAM2的根目录下的CMakeLists.txt中,将`cmake_minimum_required`的版本提高到至少2.8.12以上,推荐3.0以上。例如: ```cmake # 修改前可能是 cmake_minimum_required(VERSION 2.8) # 修改为 cmake_minimum_required(VERSION 3.0) ``` ### 2. 解决策略CMP0022警告 在同一个CMakeLists.txt文件中,在`cmake_minimum_required`命令之后,添加: ```cmake cmake_policy(SET CMP0022 NEW) ``` ### 3. 解决OpenCV版本未找到的问题 根据引用[2],我们需要修改CMakeLists.txt中的OpenCV查找部分,使其支持OpenCV4.4。在ORB_SLAM2的CMakeLists.txt以及DBoW2文件夹下的CMakeLists.txt中,修改find_package(OpenCV)的调用。 例如,在ORB_SLAM2根目录的CMakeLists.txt中,找到OpenCV相关的部分,修改为: ```cmake find_package(OpenCV 4.4 QUIET) if(NOT OpenCV_FOUND) find_package(OpenCV 2.4.3 QUIET) if(NOT OpenCV_FOUND) message(FATAL_ERROR "OpenCV > 2.4.3 not found.") endif() endif() ``` 同时,在`Thirdparty/DBoW2/CMakeLists.txt`和`Thirdparty/g2o/CMakeLists.txt`中,如果有类似的OpenCV查找,也进行同样的修改。 注意:如果系统中安装的是其他版本的OpenCV(比如4.5),则需要将4.4改为对应的版本号。或者,如果希望支持多个版本,可以尝试使用`find_package(OpenCV REQUIRED)`,然后检查版本,但这样可能不够健壮。建议明确指定已安装的版本。 ### 4. 解决makefile缺失问题 这个错误通常是配置步骤失败导致的。在解决上述OpenCV问题之后,重新运行CMake配置步骤应该能生成makefile。 ### 5. 其他可能的问题 - **usleep未声明错误**:根据引用[2],这可能是由于缺少头文件。在代码中添加`#include <unistd.h>`(该头文件声明了usleep)可以解决。需要在报错的文件中修改(例如,在ORB_SLAM2/src目录下的某些.cpp文件中,找到报错位置,在文件顶部添加该头文件)。 - **编译选项`-march=native`问题**:引用[3]提到删除`-march=native`可以解决一些编译问题。如果遇到与特定硬件指令相关的编译错误,可以尝试在CMakeLists.txt中删除这些选项。分别在: - ORB_SLAM2根目录的CMakeLists.txt - Thirdparty/g2o/CMakeLists.txt - Thirdparty/DBoW2/CMakeLists.txt 中查找`-march=native`并删除。 ### 操作步骤总结 1. 修改ORB_SLAM2根目录下的CMakeLists.txt: - 提升`cmake_minimum_required`版本。 - 添加`cmake_policy(SET CMP0022 NEW)`。 - 修改OpenCV查找逻辑。 - 删除`-march=native`(如果存在且需要删除)。 2. 修改Thirdparty/DBoW2/CMakeLists.txt和Thirdparty/g2o/CMakeLists.txt: - 同样的OpenCV查找逻辑修改(如果需要)。 - 删除`-march=native`(如果存在且需要删除)。 3. 在出现usleep错误的源文件中添加`#include <unistd.h>`。 4. 重新运行CMake配置: ```bash cd /path/to/ORB_SLAM2 rm -rf build # 清除之前的构建 mkdir build cd build cmake .. ``` 5. 编译: ```bash make -j4 ``` ### 相关问题 1. 如何检查系统中安装的OpenCV版本? 2. 在CMake中如何设置策略以处理其他弃用警告? 3. 如何解决ORB_SLAM2中的Boost库相关错误? </think> ### 解决ORB_SLAM2构建问题的完整指南 我将为您解决ORB_SLAM2构建中的三个关键问题: 1. CMake兼容性警告(CMake < 2.8.12) 2. OpenCV > 2.4.3未找到错误 3. Makefile缺失导致构建失败 #### 📝 步骤1:解决CMake兼容性警告 **问题原因**:您的CMakeLists.txt中使用了过时的CMake版本要求 **解决方案**:修改顶层CMakeLists.txt文件(位于ORB_SLAM2根目录) ```cmake # 修改前(约第39行) cmake_minimum_required(VERSION 2.8) # 修改后 → 提升最低版本要求 cmake_minimum_required(VERSION 3.0) # 添加以下策略设置(约第47行后) cmake_policy(SET CMP0022 NEW) # 启用新链接策略[^2] ``` #### 🔍 步骤2:解决OpenCV未找到错误 **问题原因**:项目默认查找OpenCV 2.4.3,但您已安装OpenCV 4.4 **解决方案**:修改所有CMakeLists.txt中的OpenCV检测逻辑 ```cmake # 在以下文件中修改find_package语句: # 1. ORB_SLAM2/CMakeLists.txt # 2. ORB_SLAM2/Thirdparty/DBoW2/CMakeLists.txt # 修改前 find_package(OpenCV 2.4.3 QUIET) # 修改后 → 优先查找OpenCV 4.4 find_package(OpenCV 4.4 QUIET) if(NOT OpenCV_FOUND) find_package(OpenCV 2.4.3 QUIET) # 向后兼容 if(NOT OpenCV_FOUND) message(FATAL_ERROR "OpenCV > 2.4.3 not found.") endif() endif() ``` #### 🛠️ 步骤3:解决Makefile缺失问题 **问题原因**:配置失败导致Makefile未生成 **完整构建流程**: ```bash # 1. 清除旧构建 cd ~/catkin_ws/src/ORB_SLAM2 rm -rf build # 2. 创建新构建目录 mkdir build && cd build # 3. 运行CMake(添加OpenCV路径提示) cmake .. -DOpenCV_DIR=/path/to/your/opencv/build # 4. 编译(使用-j加速) make -j$(nproc) ``` #### ️ 额外注意事项 1. **usleep未声明错误**:在报错的源文件顶部添加: ```cpp #include <unistd.h> // 解决usleep问题[^2] ``` 2. **硬件优化问题**:如引用[3]所述,删除`-march=native`: ```cmake # 在以下文件中: # ORB_SLAM2/CMakeLists.txt # Thirdparty/g2o/CMakeLists.txt # Thirdparty/DBoW2/CMakeLists.txt # 修改前: set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -O3 -march=native") # 修改后 → 移除-march=native set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -O3") ``` 3. **OpenCV路径验证**:确认OpenCV安装路径: ```bash # 查找OpenCVConfig.cmake sudo find / -name OpenCVConfig.cmake 2>/dev/null # 输出类似:/usr/local/opencv4/lib/cmake/opencv4 ``` #### ✅ 验证解决方案 ```bash # 检查CMake版本 cmake --version # 应 ≥ 3.0 # 运行完整构建流程 cd ORB_SLAM2/build cmake .. make -j4 # 成功标志:生成可执行文件Examples/Monocular/mono_tum ``` --- ### 🔍 相关问题 1. 如何正确升级系统中的CMake版本到3.0以上? 2. 当项目中既有OpenCV3又有OpenCV4时,如何指定使用特定版本? 3. 如何解决ORB_SLAM2中与Pangolin/Eigen3相关的依赖问题? 4. 在ARM架构(如Jetson)上编译ORB_SLAM2有哪些特殊注意事项? > 提示:如果仍遇到OpenCV报错,尝试在CMake命令中明确指定路径: > `cmake .. -DOpenCV_DIR=/usr/local/opencv4/share/OpenCV`[^2]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值