Emscripten: fatal error: 'tr1/unordered_map' file not found

618 Views Asked by At

So I am trying to compile the following code using emscripten:

// this is test.cpp

#include<iostream>
#include<string.h>
#include<fstream>
#include<tr1/unordered_map> //needed to use unordered maps in C++. not needed C++11 onwards
#include "C:\Users\<myusername>\Documents\PROGRAMMING\examplefolder\pugixml-1.11\src\pugixml.hpp"

#include <ctime>
#include <chrono>

int main()
{
    std::cout<<"DIS IS DA TEST";
    return 0;
}

My actual code is much larger, but I've shortened it down here to place emphasis on my main doubt (I have left all the header files I am using). This code compiles perfectly using g++ and gives all intended output.

But when I compile it to web assembly using emcc test.cpp -s WASM=1 -o TRY.html, it gives me this error:

test.cpp:4:9: fatal error: 'tr1/unordered_map' file not found
#include<tr1/unordered_map> //needed to use unordered maps in C++. not needed C++11 onwards
        ^~~~~~~~~~~~~~~~~~~
1 error generated.
emcc: error: 'C:/Users/vargh/emsdk/upstream/bin\clang++.exe -DEMSCRIPTEN -fignore-exceptions -mllvm -combiner-global-alias-analysis=false -mllvm -enable-emscripten-sjlj -mllvm -disable-lsr -Xclang -iwithsysroot/include/SDL -target wasm32-unknown-emscripten -D__EMSCRIPTEN_major__=2 -D__EMSCRIPTEN_minor__=0 -D__EMSCRIPTEN_tiny__=15 -D_LIBCPP_ABI_VERSION=2 -Dunix -D__unix -D__unix__ -flegacy-pass-manager -Werror=implicit-function-declaration --sysroot=C:\Users\vargh\emsdk\upstream\emscripten\cache\sysroot -Xclang -iwithsysroot/include\compat test.cpp -c -o C:\Users\<myusername>\AppData\Local\Temp\emscripten_temp_e9j9ld9x\test_0.o' failed (1)

Why is this file not found by emcc? Is there an alternate way to handle unordered_maps in C++?

I was using tr1 as I was facing the same error in the Stack Overflow question: C++ error: 'unordered_map' does not name a type

Could someone help me out?

1

There are 1 best solutions below

1
On BEST ANSWER

Why is this file not found by emcc? Is there an alternate way to handle unordered_maps in C++?

Because it moved to <unordered_map> in 2011.

If it is in neither place, you have a very old clang, and it has no unordered_map.