6

So I've just started off with Google's OpenFST toolkit and I'm trying out their examples. Using C++ on Eclipse Mars and upon build I get the following error:

fatal error: 'type_traits' file not found

Here's my sample program - when I'm trying from here.

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

using namespace std;

int main() {

    fst::StdVectorFst fst; 

    return 0;
}

And when I build it, I get the following errors:

/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

Is there some linker error? Why is it unable to find that header file? It does exist in the /usr/include/c++/4.2.1/tr1/ directory on my computer. What am I doing wrong?

Saturnian
  • 1,686
  • 6
  • 39
  • 65

2 Answers2

3

looks like a C compiler, trying to compile a C++ file

// 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

the file type_traits is provided by package libstdc++, see debian package search

related: clang throws error file not found when a cppheader.h file is wrapped in a wrapper.hpp file

# 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
milahu
  • 2,447
  • 1
  • 18
  • 25
  • What?? Why are you answering a 5 year old question? I don't think this is a problem anymore... Plus the answer is wrong, [see the discussion in chat](https://chat.stackoverflow.com/rooms/132427/discussion-between-n-m-and-saturnian) – JHBonarius Feb 01 '22 at 13:25
  • "Your case" is not the answer to this question. It's the answer to your problem. – JHBonarius Feb 01 '22 at 15:58
0

I counted for this problem,solved it in this way: xxx.c->xxx.cpp all in all, you should compile it in g++, not gcc

li-kiao
  • 1
  • 1