为什么 std::move 未定义,尽管编译器使用 -std=c++11 调用
Why is std::move undefined although compiler invoked with -std=c++11?
我想在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 标准库特性矩阵,std::move
(N2812( §"对标准库的影响"仅在 4.5 版中添加,并在 4.6 版中修订。
您应该将标准库版本更新到版本 4.5(至少(。你的是 4.2.1。
相关文章:
- C++中的VLA,扩展名为std=C++11
- 编译器不会使用 -std=c++11 编译智能指针
- C ++枚举范围无法使用-std=c ++ 98进行编译,但使用-std=c ++ 11可以
- std::使用 -std=gnu++11 开关编译时相等错误
- "unix" C++预处理器宏未定义 -std=c++11
- 用STD = C 11或其他标准编译Boost,例如Ash C 14
- 网站组装 |错误:'C/ObjC'不允许使用无效'-std=c++11'参数
- G++ - 警告:扩展初始值设定项列表仅适用于 -std=C++11 或 -std=GNU++11
- 如何避免每次编译时都必须键入 -std=c++11
- 无法用"-std=c++11"编译《你好世界》
- 无法在Eclipse Neon.3中同时使用-std = C 11和-l/-l选项
- Cython -STD = C 11错误,使用C和C
- 扩展初始化器列表仅可用-STD = C 11或-STD = GNU 11中的C
- 为什么将语言标准从-STD = GNU 98到-STD = GNU 11
- 为什么 std::move 未定义,尽管编译器使用 -std=c++11 调用
- 我可以安全地将编译的库与-STD = C 11和-STD = C 14
- MATLAB MEX:-STD = C 11使用,但MEX错误仍然是错误
- Makefile with -std=c++11
- CUDA 8 编译错误与 -std=gnu++11
- QT 5.7将-STD = GNU 11添加到我的编译器标志,Clobbering -Std = C 14