std::filesystem with GCC 8.3 Docker Image
I have been playing around with Docker and using it to access the latest features of GCC's libstd++
My docker file using is available here - it grabs the latest official GCC docker image
And the example it is trying to compile is
#include <iostream>
#include <filesystem>
namespace fs = std::filesystem;
int main()
{
std::cout << "Current path is " << fs::current_path() << '\n';
}
The compiler error I get is
Step 4/5 : RUN g++ -o hello_world main.cpp -lstdc++fs
---> Running in 380d3c669bf9
main.cpp:3:21: error: 'filesystem' is not a namespace-name
namespace fs = std::filesystem;
^~~~~~~~~~
main.cpp:3:31: error: expected namespace-name before ';' token
namespace fs = std::filesystem;
^
main.cpp: In function 'int main()':
main.cpp:6:40: error: 'fs' has not been declared
std::cout << "Current path is " << fs::current_path() << '\n';
I have confirmed that I have the expect version of compiler
Step 4/5 : RUN g++ --version
---> Running in 7bea4b71ec56
g++ (GCC) 8.3.0
Any suggestions?
Posted Apr 20, 2019, 2:15 AM UTC
63
Add
-std=c++17to your compiler switches.https://godbolt.org/z/4k7h4o
Don't forget the
-lstdc++fs(source: https://en.cppreference.com/w/cpp/filesystem )Thanks for this. I just assumed -lstd++fs would enable all the required features