I'm having problems getting any output from the std::filesystem
functions in C++
, even from the most simple functions like current_path
. I'm compiling with mingw64, g++
on Windows, it comes with C++17
support and experimental C++20
support which I've enabled, but regardless of C++
version, I'm getting no output. This is the tasks.json
I'm using with Visual Studio code:
"type": "cppbuild",
"label": "C/C++: g++.exe build active file",
"command": "C:\\msys64\\mingw64\\bin\\g++.exe",
"args": [
"-fdiagnostics-color=always",
"-g",
"${file}",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe",
"-std=gnu++20"
],
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": [
"$gcc"
],
"group": "build",
"detail": "compiler: C:\\msys64\\mingw64\\bin\\g++.exe"
I've tried running some very simple examples from here, such as:
#include <iostream>
#include <filesystem>
namespace fs = std::filesystem;
int main()
{
std::cout << "Current path is " << fs::current_path() << '\n'; // (1)
fs::current_path(fs::temp_directory_path()); // (3)
std::cout << "Current path is " << fs::current_path() << '\n';
}
Which returns no output at all. Another thing I wanted to do was listing the files in a certain directory like this:
#include <string>
#include <iostream>
#include <filesystem>
namespace fs = std::filesystem;
int main()
{
std::string path = "C:\\Users\\MyName\\Desktop";
for (const auto & entry : fs::directory_iterator(path))
std::cout << entry.path() << std::endl;
}
Which again, returns absolutely no output. I don't know what I'm doing wrong and I've not been able to find anybody else with this problem.
While writing the question I've found an answer that works here, that is, adding the -static
argument to g++
to avoid dynamic linking. I'm not familiar with these minutiae yet, but is there no way to avoid static building in my case?