【问题标题】:fatal error: 'type_traits' file not found致命错误:找不到“type_traits”文件
【发布时间】:2017-01-05 06:09:41
【问题描述】:

所以我刚刚开始使用 Google 的 OpenFST 工具包,并且正在尝试他们的示例。在 Eclipse Mars 上使用 C++ 并在构建时出现以下错误:

fatal error: 'type_traits' file not found

这是我的示例程序 - 当我从 here 尝试时。

#include <iostream>
#include <fst/fst-decl.h>
#include <fst/fstlib.h>

using namespace std;

int main() {

    fst::StdVectorFst fst; 

    return 0;
}

当我构建它时,我收到以下错误:

/usr/local/include/fst/util.h:15:10: fatal error: 'type_traits' file not found
#include <type_traits>
         ^
1 error generated.
make: *** [src/sampleFST.o] Error 1

是否存在链接器错误?为什么找不到那个头文件?它确实存在于我计算机上的/usr/include/c++/4.2.1/tr1/ 目录中。我做错了什么?

【问题讨论】:

  • gcc 4.2 是化石。升级。
  • gcc 6.0 是最新的吗?
  • 6.3 和 5.4 是最新的,但任何 5 或 6 版本都应该这样做。
  • @n.m.我刚刚升级了我的 gcc,但错误仍然存​​在 :(
  • 您可能需要将 -std=c++11 标志传递给 g++。

标签: c++ eclipse-cdt typetraits openfst


【解决方案1】:

看起来像一个 C 编译器,试图编译一个 C++ 文件

// test.h
#include <type_traits>
clang -c test.h
# test.h:1:10: fatal error: 'type_traits' file not found

gcc -c test.h
# test.h:1:10: fatal error: type_traits: No such file or directory

# solutions ...

# fix file extension
gcc -c test.hh
clang -c test.hh

# set language in compiler flag
gcc -c -x c++ test.h
clang -c -x c++ test.h

# set language in compiler command
g++ -c in.h
clang++ -c in.h

文件type_traits由包libstdc++提供, 见debian package search

相关:当 cppheader.h 文件包含在 wrapper.hpp 文件中时,clang 会抛出错误 file not found

# cppheader.h has wrong file extension, should be hh/hpp/hxx
echo '#include <type_traits>' >cppheader.h
echo '#include "cppheader.h"' >wrapper.hpp

# error with clang
clang -c wrapper.hpp # -> fatal error: 'type_traits' file not found

# works with gcc
gcc -c wrapper.hpp

【讨论】:

  • 什么?你为什么要回答一个 5 岁的问题?我不认为这是一个问题了......加上答案是错误的,see the discussion in chat
  • “你的情况”不是这个问题的答案。这是您问题的答案。
猜你喜欢
  • 1970-01-01
  • 2016-12-21
  • 2020-10-02
  • 2015-01-20
  • 2014-12-21
  • 2013-12-10
  • 1970-01-01
  • 2022-07-13
  • 1970-01-01
相关资源
最近更新 更多