c ++ 11 #include< thread>给出编译错误 [英] c++11 #include <thread> gives compile error
问题描述
当尝试从已编译的源文件创建对象文件时,我收到编译错误。我使用与c ++ 11一起提供的标题。我还使用一个c ++模式识别库与其他几个包括。
I get a compile error when trying to create an object file from a compiled source file. I am using the header which came with c++11. I am also using a c++ pattern recognition library with several other includes.
我所做的是添加 #include< thread>
to my rbm_test.cc source file。
All I did was add #include <thread>
to my rbm_test.cc source file.
我的编译命令:
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 _-rbm_test.o -c。 ./src/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编译器选项启用。
error: #error This file requires compiler and library support for the ISO C++ 2011 standard. This support is currently experimental, and must be enabled with the -std=c++11 or -std=gnu++11 compiler options.
奇怪的是,当我用
g ++ -std = c ++ 11 -pthread - c main.cpp -o main.o
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();
}
当我尝试编译时,有些编译标志可能会冲突rbm_test.cc?
Is it possible that some of the compile flags are conflicting when I try to compile rbm_test.cc?
推荐答案
- ansi
code> -std = c ++ 11 标志。 -ansi
等效于 -std = c ++ 98
。删除 -ansi
标志可解决此问题。
The -ansi
flag conflicts with the -std=c++11
flag. -ansi
is equivalent to -std=c++98
. Removing the -ansi
flag solves the problem.
这篇关于c ++ 11 #include< thread>给出编译错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!