c ++ 11 #include <thread>给出编译错误

mcv*_*cvz 2 c++ compiler-errors g++ pthreads

尝试从已编译的源文件创建目标文件时出现编译错误.我正在使用c ++ 11附带的标题.我还使用了c ++模式识别库和其他几个包含.

我所做的就是添加#include <thread>到我的rbm_test.cc源文件中.

我的编译命令:

g ++ -std = c ++ 11 -O3 -DQUIET -fPIC -pthread -ansi -pedantic -DARCH_INTEL -Wall -W -Wchar-subscripts -Wpointer-arith -Wcast-qual -Wwrite-strings -Wconversion -Wno-old-style -cast -Wctor-dtor-privacy -Wnon-virtual-dtor -I ../ src -I ../ .. -DPATREC -D_ UNIX _ -o rbm_test.o -c ../src/rbm_test.cc

我得到的编译错误是:

错误:#error此文件需要ISO C++ 2011标准的编译器和库支持.此支持目前是实验性的,必须使用-std = c ++ 11或-std = gnu ++ 11编译器选项启用.

奇怪的是,当我编译下面的代码示例时

g ++ -std = c ++ 11 -pthread -c main.cpp -o main.o

那我没有错.

这是 main.cpp

#include <iostream>
#include <thread>

void f1()
{
  std::cout << "Thread  executing\n";
}

int main()
{
    std::thread t1(f1);
    std::thread t2(f1);
    t1.join();
    t2.join();
}
Run Code Online (Sandbox Code Playgroud)

当我尝试编译rbm_test.cc时,是否有可能某些编译标志发生冲突?

mcv*_*cvz 8

- ansi标志与旗帜冲突-std=c++11.-ansi相当于-std=c++98.删除-ansi标志可以解决问题.