fatal error: 'type_traits' file not found
Asked Answered
D

2

8

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?

Darwindarwinian answered 5/1, 2017 at 6:9 Comment(7)
gcc 4.2 is a fossil. Upgrade.Bustard
gcc 6.0 is latest?Darwindarwinian
6.3 and 5.4 are current but any 5 or 6 version should do.Bustard
@n.m. I just upgraded my gcc but the error still persists :(Darwindarwinian
You probably need to pass -std=c++11 flag to g++.Bustard
I am doing that. I added -stdlib=libstdc++ -std=c++11 but still the error persists :(Darwindarwinian
Let us continue this discussion in chat.Bustard
A
6

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
Aludel answered 31/1, 2022 at 19:5 Comment(2)
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 chatAuthorization
"Your case" is not the answer to this question. It's the answer to your problem.Authorization
K
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

Kablesh answered 3/11, 2022 at 2:29 Comment(1)
did not work for mePashalik

© 2022 - 2024 — McMap. All rights reserved.