c++11 #include 给出编译错误

2024-04-23

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

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

我的编译命令:

g++ -std=c++11 -O3 -DQUIET -fPIC -pthread -ansi -pedantic -DARCH_INTEL -Wall -W -Wchar-下标 -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

那么我就没有错误了。

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

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


The -ansi标志与-std=c++11 flag. -ansi相当于-std=c++98。删除-ansi标志解决了问题。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

c++11 #include 给出编译错误 的相关文章

随机推荐