C++编译器不支持C++11(例如std::unique_ptr)构建OpenWrt

The C++ compiler does not support C++11 (e.g. std::unique_ptr) building OpenWrt

本文关键字:unique ptr OpenWrt 构建 std 不支持 编译器 C++11 例如 C++      更新时间:2023-10-16

我在这里和这里使用说明在Ubuntu中构建OpenWrt,但我得到:

make[4]: Entering directory '~/openwrt/build_dir/host/cmake-3.11.1/Bootstrap.cmk'
make[4]: 'cmake' is up to date.
make[4]: Leaving directory '~/openwrt/build_dir/host/cmake-3.11.1/Bootstrap.cmk'
loading initial cache file ~/openwrt/build_dir/host/cmake-3.11.1/Bootstrap.cmk/InitialCacheFlags.cmake
CMake Error at CMakeLists.txt:92 (message):
The C++ compiler does not support C++11 (e.g.  std::unique_ptr).

-- Configuring incomplete, errors occurred!

这里有一个类似问题的解决方案。但是,我不清楚哪个CMakeLists.txt文件是我的情况下的"根"。我在OpenWrt论坛(或一般的搜索引擎)上没有看到太多关于这个失败的信息。

我得到的印象是CMake安装是由OpenWrt构建器本身下载的,因为我没有安装CMake并且安装CMake什么也解决不了。

尝试查看最新的OpenWrt v18.06.2。当构建失败时,我删除了克隆的目录并尝试了 v18.06.0-rc2。没有改善。

我也试过

export CMAKE_CXX_STANDARD=11

在运行"make"之前,但它没有解决问题。

我的 g++ 安装状态:

g++ -v

输出:

Using built-in specs.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/7/lto-wrapper
OFFLOAD_TARGET_NAMES=nvptx-none
OFFLOAD_TARGET_DEFAULT=1
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu 7.3.0-27ubuntu1~18.04' --with-bugurl=file:///usr/share/doc/gcc-7/README.Bugs --enable-languages=c,ada,c++,go,brig,d,fortran,objc,obj-c++ --prefix=/usr --with-gcc-major-version-only --program-suffix=-7 --program-prefix=x86_64-linux-gnu- --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-vtable-verify --enable-libmpx --enable-plugin --enable-default-pie --with-system-zlib --with-target-system-zlib --enable-objc-gc=auto --enable-multiarch --disable-werror --with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic --enable-offload-targets=nvptx-none --without-cuda-driver --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu
Thread model: posix
gcc version 7.3.0 (Ubuntu 7.3.0-27ubuntu1~18.04)

嗯,那是五个小时,我没主意了。这可能是配置错误还是开发人员端的错误?

如果配置错误,可能设置错误?

我的解决方案很简单:

我将 CMake 源代码复制到我的系统驱动器。如果您在远程硬盘驱动器上制作CMake,它将失败并像上面一样出错。

我的糟糕经历可以帮助其他人。 我有 GCC 7.4.0。在同一台机器上,我在配置软件包时没有任何问题。有一天,我决定构建一个优化版本,

export CXXFLAGS=O3
configure
... many lines ignored
checking whether g++ supports C++11 features by default... no
checking whether g++ supports C++11 features with -std=c++11... no
checking whether g++ supports C++11 features with +std=c++11... no
checking whether g++ supports C++11 features with -h std=c++11... no
checking whether g++ supports C++11 features with -std=c++0x... no
checking whether g++ supports C++11 features with +std=c++0x... no
checking whether g++ supports C++11 features with -h std=c++0x... no
configure: error: *** A compiler with support for C++11 language features is required.

注意:导出CXXFLAGS="-O3">后,我的问题消失了。 拼写错误缺少破折号。我希望这可以帮助许多其他人。大多数困难都是由我们犯的微妙错误造成的。

我在gentoo常见的x86 PC中遇到了完全相同的问题(不是交叉构建),所以这一定是他们的错误,不是你的错,也不是我的错。

[1] Gentoo bug - https://bugs.gentoo.org/691544, [2] 你提出的解决方案 - https://thelinuxcluster.com/2021/10/01/the-c-compiler-does-not-support-c11-during-bootstrap-for-cmake/

因此,尽管在将 c 标志设置为"-O3"并将点挂载到本地驱动器或以"mount -o remount/"的形式出现时可能会有一些解决方法,但我个人建议修补 make 文件,不要错误地尝试检查这些 C++11 功能。

cmake-3.21.4中,我从文件"CMakeLists.txt"中删除了十行,即 99 ~ 109。这是 的 .diff 文件

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 9944ea4c..195fd842 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -96,17 +96,7 @@ if(NOT DEFINED CMAKE_CXX_STANDARD AND NOT CMake_NO_CXX_STANDARD)
endif()
endif()
endif()
-if(NOT CMake_TEST_EXTERNAL_CMAKE)
-  # include special compile flags for some compilers
-  include(CompileFlags.cmake)
-
-  # check for available C++ features
-  include(${CMake_SOURCE_DIR}/Source/Checks/cm_cxx_features.cmake)

-  if(NOT CMake_HAVE_CXX_UNIQUE_PTR)
-    message(FATAL_ERROR "The C++ compiler does not support C++11 (e.g. std::unique_ptr).")
-  endif()
-endif()

# Inform STL library header wrappers whether to use system versions.
configure_file(${CMake_SOURCE_DIR}/Utilities/std/cmSTL.hxx.in

当然,只有当你确定你的编译器支持 C+11 时,才这样做(就像 2000 年代后期以来的任何 gcc

)。

尝试解决方案

vim /etc/profile
export LC_ALL=C
unset LANGUAGE
source /etc/profile

如果您发现setlocate警告。

在设置MAKEFLAGS(设置为"-j8")时,我遇到了同样的错误(在Linux桌面上,与OpenWrt无关)。这是因为警告gmake[1]: warning: -jN forced in submake: disabling jobserver mode.使CMake测试认为出了问题。咄。 解决办法:unset MAKEFLAGS.

在任何情况下,调查此错误的方法是读取CMakeFiles/CMakeError.log