【发布时间】:2017-01-18 18:51:07
【问题描述】:
我可以使用以下命令使用 g++ 编译以下 std=c++11 所需的代码:
g++ test.cpp -std=c++11 -Wl,-rpath,/share/apps/gcc/6.3.0/lib64
代码:
#include <chrono>
#include <map>
#include <memory>
#include <thread>
#include <utility>
int main() {
typedef std::unique_ptr<int> intPointer;
intPointer p(new int(10));
std::map<int, std::unique_ptr<int>> m;
m.insert(std::make_pair(5, std::move(p)));
auto start = std::chrono::system_clock::now();
if (std::chrono::system_clock::now() - start < std::chrono::seconds(2))
{
std::thread t;
}
}
相同的命令(可能我不知道正确的命令)不适用于 intel 编译器:
icpc test.cpp -std=c++11 -Wl,-rpath,/share/apps/intel/2016.1.056/vtune_amplifier_xe_2016.1.1.434111/target/linux64/lib64
错误是:
In file included from /share/apps/gcc/6.3.0/include/c++/6.3.0/map(60),
from test.cpp(2):
/share/apps/gcc/6.3.0/include/c++/6.3.0/bits/stl_tree.h(1437):
error: identifier "_Compare" is undefined
&& is_nothrow_move_assignable<_Compare>::value)
^
In file included from /share/apps/gcc/6.3.0/include/c++/6.3.0/map(60),
from test.cpp(2):
/share/apps/gcc/6.3.0/include/c++/6.3.0/bits/stl_tree.h(1778):
error: identifier "_Compare" is undefined
_GLIBCXX_NOEXCEPT_IF(__is_nothrow_swappable<_Compare>::value)
^
我做错了什么,我应该如何解决这个问题。
【问题讨论】:
-
您的英特尔编译器使用 GCC 头文件是否正常?我有一种行不通的感觉。也许您应该使用 Intel 的等价物。
-
好吧,这段代码不是我写的。它是编译更大软件的测试的一部分。如果这段代码没有返回错误,它让我编译。所以改变代码不是我能做的。那是坚实而给定的。
-
你这么说,但你的编译器不同意。每个供应商都有自己的标准库实现,您不能随意将标头与编译器混合和匹配。
-
_Compare是该文件中定义的_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>的模板参数之一,所以肯定是定义的。一个怀疑是英特尔编译器可能不知道is_nothrow_move_assignable最近添加到 type_traits 中。可能需要提交错误报告。 -
@tadman 这完全正常。 ICC 搭载平台编译器的标准库实现(GCC 用于 Linux,MSVC 用于 Windows)。它没有自己的标准库实现。