I'm trying to get a program using the <filesystem>
library running on Windows. I'm using MSYS2's (64 Bit) g++
.
#include <iostream>
#include <filesystem>
int main()
{
std::cout << "Hello World\n";
std::cout << "Current path is " << std::filesystem::current_path() << '\n';
}
I'm building it with
g++ -std=c++17 -Wall -Werror -Wextra main.cpp -lstdc++fs
I get no console output from the compiler. It silently generates an a.exe
. Executing the a.exe
just does nothing. There is no output and no errors. $?
(which is said to contain a program's return code) is 127
after running the program.
g++ -v
prints:
Using built-in specs.
COLLECT_GCC=C:\msys64\mingw64\bin\g++.exe
COLLECT_LTO_WRAPPER=C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/9.1.0/lto-wrapper.exe
Target: x86_64-w64-mingw32
Configured with: ../gcc-9.1.0/configure --prefix=/mingw64 --with-local-prefix=/mingw64/local --build=x86_64-w64-mingw32 --host=x86_64-w64-mingw32 --target=x86_64-w64-mingw32 --with-native-system-header-dir=/mingw64/x86_64-w64-mingw32/include --libexecdir=/mingw64/lib --enable-bootstrap --with-arch=x86-64 --with-tune=generic --enable-languages=c,lto,c++,fortran,ada,objc,obj-c++ --enable-shared --enable-static --enable-libatomic --enable-threads=posix --enable-graphite --enable-fully-dynamic-string --enable-libstdcxx-filesystem-ts=yes --enable-libstdcxx-time=yes --disable-libstdcxx-pch --disable-libstdcxx-debug --disable-isl-version-check --enable-lto --enable-libgomp --disable-multilib --enable-checking=release --disable-rpath --disable-win32-registry --disable-nls --disable-werror --disable-symvers --enable-plugin --with-libiconv --with-system-zlib --with-gmp=/mingw64 --with-mpfr=/mingw64 --with-mpc=/mingw64 --with-isl=/mingw64 --with-pkgversion='Rev3, Built by MSYS2 project' --with-bugurl=https://sourceforge.net/projects/msys2 --with-gnu-as --with-gnu-ld
Thread model: posix
gcc version 9.1.0 (Rev3, Built by MSYS2 project)
What could be wrong?
(I get a Hello World
output and $?
is 0
, if I comment out the line with the std::filesystem::current_path()
call, so the compiler is working.)
ldd
on the executable lists no errors. However, there are three DLLs taken from MinGW64, which might be outdated. I'm looking how to make it use the ones from MSYS64 right now. – Polliecurrent_path
can throw exceptions. See here: en.cppreference.com/w/cpp/filesystem/current_path – Pricillaprickerror_code
and print that after the call. Still nothing printed at all. – Polliecurrent_path()
. At some point, the WinAPIGetCurrentDirectory()
will propably be called. See if it fails. – Windbrokengdb
says During startup program exited with code 0xc0000139. – Pollieg++
from MSYS, but the DLLs from Git Bash. It works when using the native MSYS terminal. I will write an answer soon. – Pollie