I have typed g++ --version on may computer got following message:
g++ (GCC) 8.0.0 20170430 (experimental)
Copyright (C) 2017 Free Software Foundation, Inc.
Then I typed following g++ command and I am getting error with filesystem include file as shown below:
g++ -std=c++17 browse_files_in_dir.cpp -o browse_files
browse_files_in_dir.cpp:3:10: fatal error: filesystem: No such file or directory
#include <filesystem>
^~~~~~~~~~~~
compilation terminated.
I have pasted c++ code below.
Is filesystem library features not supported by the gcc 8.0.0 please?
1 2 3 4 5 6 7 8 9 10 11
#include <string>
#include <iostream>
#include <filesystem>
namespace fs = std::filesystem;
int main()
{
std::string path = "C:\\cpp_filesystem";
for (auto & p : fs::directory_iterator(path))
std::cout << p << std::endl;
}
Many thanks for the information.
I tried and it is still giving error:
g++ -std=c++17 browse_files_in_dir.cpp -o file_browser
browse_files_in_dir.cpp:3:10: fatal error: experimental/filesystem: No such file or directory
#include <experimental/filesystem>
^~~~~~~~~~~~~~~~~~~~~~~~~
compilation terminated.
I looked at the following folder path in which gcc 8.0.0 is installed and the filesystem file is not in this folder. Any way to find the filesystem file please?
AFAIK the GNU implementation of the filesystem TS is not part of their standard C++ library; it is in a separate library called libstdc++fs.a. This library is not available / is thoroughly broken on non-posix platforms.
On my system the libray file is built with debug info, so the executable comes out quite large. This was fixed by using objcopy -g with the executable file, on Linux. It might be different on Windows.
Thanks to mbozzi for helping me with that.
Edit:
Filesystem is a technical specification (as opposed to the core language), you might need -std=gnu++1z or -std=c++1z flag instead of -std=c++17 to use it - I did.
I looked in my computer's path C:\gcc_8\gcc\lib
I did not find libstdc++fs.a file. I have only libstdc++.a file on my windows 10 computer.
Thanks again.
TheIdeasMan,
Thanks for info.
I tried both as follows and both did not file the filesystem include file:
C:\cpp\browse_files_in_dir>g++ -std=c++1z browse_files_in_dir.cpp -o file_browser
browse_files_in_dir.cpp:3:10: fatal error: experimental/filesystem: No such file or directory
#include <experimental/filesystem>
^~~~~~~~~~~~~~~~~~~~~~~~~
C:\cpp\browse_files_in_dir>g++ -std=gnu++1z browse_files_in_dir.cpp -o file_browser
browse_files_in_dir.cpp:3:10: fatal error: experimental/filesystem: No such file or directory
#include <experimental/filesystem>
^~~~~~~~~~~~~~~~~~~~~~~~~
compilation terminated.
I searched for filesystem file in Windows explorer and found it in Microsoft\Visual Studio 9.0\VB folder. But this is NOT the file C++ compiler needs I believe.
Beautiful. Above Microsoft compiler information is very helpful.
I have downloaded Microsoft Visual Studio Community Edition 2017 from Microsoft.com
The example filesystem program you have provided at the above cplusplus.com link
beginner/211374/#msg990138 worked like a charm. The program re-cursed through folders and listed using cout the folder names and file names.
Many, many thanks for very useful information.
May I please know links to other example programs that utilize various filesystem features to perform various text files processing utilities?