python - 尽管使用 -std=c++11 调用了编译器,但为什么 std::move 未定义?

标签 python c++ c++11 move

我想在 OSX 上编译 kenlm,但出现错误:

error: no member named 'move' in namespace 'std'

其他帖子建议用

编译

'-std=c++11'

但我仍然遇到同样的错误。我该如何解决这个问题?

g++ --version 输出:

Configured with: --prefix=/Library/Developer/CommandLineTools/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
Apple LLVM version 8.1.0 (clang-802.0.38)
Target: x86_64-apple-darwin16.5.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin

kenlm 的构建脚本如下所示:

from setuptools import setup, Extension
import glob
import platform
import os

#Does gcc compile with this header and library?
def compile_test(header, library):
    dummy_path = os.path.join(os.path.dirname(__file__), "dummy")
    command = "bash -c \"g++ -include " + header + " -l" + library + " -x c++ - <<<'int main() {}' -o " + dummy_path + " >/dev/null 2>/dev/null && rm " + dummy_path + " 2>/dev/null\""
    return os.system(command) == 0
...

#We don't need -std=c++11 but python seems to be compiled with it now.  https://github.com/kpu/kenlm/issues/86
ARGS = ['-O3', '-DNDEBUG', '-DKENLM_MAX_ORDER=6', '-std=c++11']
ext_modules = [
    Extension(name='kenlm',
        sources=FILES + ['python/kenlm.cpp'],
        language='C++', 
        include_dirs=['.'],
        libraries=LIBS, 
        extra_compile_args=ARGS)
]
...

使用 std::move 的代码:

#ifndef UTIL_FILE_STREAM_H
#define UTIL_FILE_STREAM_H
#include <utility>
#include "util/fake_ostream.hh"
#include "util/file.hh"
#include "util/scoped.hh"

#include <cassert>
#include <cstring>

#include <stdint.h>

namespace util {

class FileStream : public FakeOStream<FileStream> {
  public:
    explicit FileStream(int out = -1, std::size_t buffer_size = 8192)
      : buf_(util::MallocOrThrow(std::max<std::size_t>(buffer_size, kToStringMaxBytes))),
        current_(static_cast<char*>(buf_.get())),
        end_(current_ + std::max<std::size_t>(buffer_size, kToStringMaxBytes)),
        fd_(out) {}

#if __cplusplus >= 201103L
    FileStream(FileStream &&from) noexcept : buf_(std::move(from.buf_)), current_(from.current_), end_(from.end_), fd_(from.fd_) {
      from.end_ = reinterpret_cast<char*>(from.buf_.get());
      from.current_ = from.end_;
    }
#endif

最佳答案

根据GNU CC Standard Library feature matrix , std::move (N2812) §"Impact on the Standard Library"仅在4.5版本中加入,在4.6版本中进行了修改。

您应该将标准库版本更新到 4.5 版(至少)。你的是 4.2.1。

关于python - 尽管使用 -std=c++11 调用了编译器,但为什么 std::move 未定义?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43370410/

相关文章:

python - ValueError : tf. 函数装饰函数试图在非第一次调用时创建变量

python - 在 Ubuntu 上使用 Python 的 Azure WebApp 中的连接泄漏

Python - 如何删除以数字开头并包含句点的单词

c++ - 用谷歌测试重载函数

c++ - 重载时在定义之前声明函数模板

python - 从 PySpark 中的工作节点访问 ADLS 上的二进制文件的最有效方法?

C++11 static assert for equality comparable type?

c++ - 什么是 C++ 原子变量?

c++ - 如果第二个属性未进行大括号初始化,则与大括号初始化程序编译成对缩小转换

c++ - 为什么添加 `const` 会使通用引用成为右值