简体   繁体   中英

c++11 #include <thread> gives compile error

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.

All I did was add #include <thread> to my rbm_test.cc source file.

My compile command:

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

The compile error I get is:

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.

Strangely, when I compile the following code example with

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

then I have no error.

Here Is 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();
}

Is it possible that some of the compile flags are conflicting when I try to compile rbm_test.cc?

The - ansi flag conflicts with the -std=c++11 flag. -ansi is equivalent to -std=c++98 . Removing the -ansi flag solves the problem.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM