2

尝试从已编译的源文件创建目标文件时出现编译错误。我正在使用 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();
}

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

4

1 回答 1

8

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

于 2013-03-26T08:14:09.733 回答