0

I just wanna to print the current path and its content, via std::filesystem::path::current_path (the compiler is emcc this one). Some code below:

//... some stuff ...
namespace fs = 
#if defined(_MSC_VER) || defined(_WIN32) 
  std::filesystem;
#else
  std::__fs::filesystem;
#endif
//... some stuff ...
cfg::Config::Config() { this->Path = fs::current_path(); }

void cfg::Config::getPath()
{
    for (auto &p : fs::directory_iterator(this->Path)) std::cout << p.path() << '\n';
}

And for windows it works fine, the output looks like:

...
"D:\\GitHub\\Emscripten_OpenGL\\build\\cmake_install.cmake"
"D:\\GitHub\\Emscripten_OpenGL\\build\\Debug"
"D:\\GitHub\\Emscripten_OpenGL\\build\\Emscripten_Graphics.dir"
"D:\\GitHub\\Emscripten_OpenGL\\build\\Emscripten_Graphics.sln"
"D:\\GitHub\\Emscripten_OpenGL\\build\\Emscripten_Graphics.vcxproj"
"D:\\GitHub\\Emscripten_OpenGL\\build\\Emscripten_Graphics.vcxproj.filters"
"D:\\GitHub\\Emscripten_OpenGL\\build\\Emscripten_Graphics.vcxproj.user"
...

However, whether for Linux subsystem or for docker container with Ubuntu image it just prints the root directory:

application_1  | [100%] Built target Emscripten_Graphics
application_1  | make: make
application_1  | "/tmp"
application_1  | "/home"
application_1  | "/dev"
application_1  | "/proc"

May be I something missed apropos the Linux's std::filesystem?

JuiceFV
  • 171
  • 11
  • `std::__fs::filesystem;` you should not use any symbol starting with double underscore. Can you explain way you are doing that? Did you forgot to enable C++17 on Linux? – Marek R Oct 07 '20 at 12:22
  • Wha version of `GCC` are you using? Current versions have `std::filesystem` and older versions have `std::experimental::filesystem`. I've never seen `std::__fs::filesystem` though. – Galik Oct 07 '20 at 12:27
  • @Marek R yep, I do that because in other way it raises an exception (`std::filesystem` not found and the system recommends to use this one). I'm using `emcc` [compiler](https://emscripten.org/). – JuiceFV Oct 07 '20 at 12:31
  • Do you understand the concept of a working directory? What working directory do you expect your Docker program to run in? Did you specify any [WORKDIR](https://docs.docker.com/engine/reference/builder/#workdir) in the Dockerfile? – rustyx Oct 07 '20 at 12:47
  • @rustyx I did specify. It should be something like `app/build/...`. As I currently comprehend it's occurring because of the compiler. – JuiceFV Oct 07 '20 at 12:54
  • I wouldn't be so sure. How do you know your Dockerfile is correct? Did you check that the program actually starts in the specified directory? – rustyx Oct 07 '20 at 13:05
  • @rustyx In other way it might not be able to find `CMakeLists.txt` in the WORKDIR. And if even the Dockerfile is wrong, I've tried to do the same manually in the linux subsystem the output the same. – JuiceFV Oct 07 '20 at 13:09
  • 1
    if you run compiled with `emcc` version - it "mounts" virtual filesystem where everything starts from root and it is probably the case. – Sugar Oct 07 '20 at 14:02

1 Answers1

0

I found a solution, so it's may be useful to others. Thanks to @Sugar I dug in the Emscripten Filesystem API. The emscripten creates its own virtual filesystem and uploading there files used in c++ code. According to this issue the way to fix it is to add the -s NODERAWFS=1 as flag, whilst compile.

JuiceFV
  • 171
  • 11