嘗試從編譯源文件創建目標文件時出現編譯錯誤。我正在使用C++ 11附帶的頭文件。我還使用了一個C++模式識別庫與其他幾個包括。C++ 11 #include <thread>給出編譯錯誤
我所做的只是將#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: #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
下面的代碼示例那我也沒錯誤。
這裏是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是衝突的?
好吧,就像我發佈的問題,我找到了解決方案。 -ansi標誌與-std = C++ 11標誌衝突。 -ansi相當於-std = C++ 98。移除-ansi標誌解決了這個問題。 – mcvz 2013-03-26 08:10:43
是的,那就是我正在建議的。您可以將其發佈爲答案並選擇它。 – juanchopanza 2013-03-26 08:11:23
我可能錯過了它,但包含編譯器版本是個好主意。 – 2013-03-26 08:12:23