【问题标题】:The C++ compiler does not support C++11 (e.g. std::unique_ptr). building OpenWRTC++ 编译器不支持 C++11(例如 std::unique_ptr)。构建 OpenWRT
【发布时间】:2019-04-20 10:45:31
【问题描述】:

我正在使用指令 herehere 在 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!

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

我得到的印象是 CMake 安装是由 OpenWRT 构建器本身下载的,因为我没有安装 CMake 并且安装 cmake 没有解决任何问题。

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

也试过了

导出 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)

嗯,那是 5 个小时我没有想法。这可能是开发端的错误配置或错误吗?

如果配置错误,可能是什么设置错误?

【问题讨论】:

  • g++ 接受命令行选项以支持更新的标准。例如g++ -std=c++11。 AFAIK,它不会检查环境变量来启用类似的东西。您需要配置构建脚本以提供这些命令行选项。默认的“方言”取决于 gcc/g++ 版本,但往往默认为稳定性而不是最新版本(例如,可以肯定的是,2018 年的 gcc 版本将默认支持 C++14 甚至更早,而不是 C ++17 - 因此使用 C++17 需要您提供所需的命令行选项)。
  • @Peter 感谢您的输入,但它甚至不是我的 make 脚本——它是 OpenWRT——它在具有相同软件包的相同操作系统版本的全新 VM 安装上完成。我的构建环境中有一些东西坏了,我对它在哪里感到困惑。我什至重新安装了我所有的开发包,没有任何改善。

标签: c++ cmake g++ openwrt


【解决方案1】:

我在这里粘贴我的解决方案,以便有人可能会得到我的提示(或者可能不是因为这个原因)

在搜索了数百万个页面后,人们只是谈论为什么而不是如何,我的解决方案很简单:

将 cmake 源代码复制到我的系统驱动器。如果你在远程硬盘上制作 cmake,它会像上面一样失败和错误

【讨论】:

    【解决方案2】:

    我的糟糕经历可以帮助其他人。我有 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.
    

    注意:在执行 export CXXFLAGS="-O3" 之后,我的问题就消失了。错字缺少破折号。希望这可以帮助许多其他人。大多数困难都是由我们犯的细微错误造成的。

    【讨论】:

    • export CXXFLAGS="-O3" 确实解决了我两周的头痛问题。非常感谢@Kemin Shou 的分享。
    【解决方案3】:

    还有几个关于这个错误的抱怨。

    我很快发现 1) stackoverflow 上的一个线程,他们指责交叉构建 [The C++ compiler does not support C++11 (e.g. std::unique_ptr). building OpenWRT],2) 博客中的一个帖子,他们指责挂载目录和 c 标志 [https://thelinuxcluster.com/2021/10/01/the-c-compiler-does-not-support-c11-during-bootstrap-for-cmake/],3) 一个 gitlab 线程,其中他们责怪 distcc [https://gitlab.kitware.com/cmake/cmake/-/issues/22573],4) 在官方 CMake 论坛上的一个讨论,他们责怪 windows [https://discourse.cmake.org/t/cmake-error-at-cmakelists-txt-117-message-the-c-compiler-does-not-support-c-11-e-g-std-unique-ptr/3774] 最后但至少是一个 gentoo 错误,他们也责怪环境变量 [https://bugs.gentoo.org/691544]。

    他们每个人都找到了不同的解决方法:将构建移动到另一个目录,重新挂载存储点,将 c 标志更改为“-O3”,为 linux 实现切换 windows 子系统,强制使用 C++14 等。

    我个人绕过了这个检查,因为我确信我的编译器支持 C++11 功能,比如“std:unique_ptr”,尽管 Cmake 抱怨。这不是一个明确的补丁,但由于它是自 2000 年代后期以来的标准,所以很少有人不应该支持 C++11,而那些不支持的人必须非常清楚他们在做什么。

    这是我在 'cmake-3.21.4' 中使用的补丁

    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
    

    【讨论】:

      【解决方案4】:

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

      无论如何,调查这个错误的方法是阅读 CMakeFiles/CMakeError.log

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2018-01-13
        • 1970-01-01
        • 2019-11-07
        • 1970-01-01
        • 2014-01-30
        • 2013-08-13
        相关资源
        最近更新 更多