diff --git a/doc/source/faq.rst b/doc/source/faq.rst index f7d5461a..9fb44e38 100644 --- a/doc/source/faq.rst +++ b/doc/source/faq.rst @@ -39,6 +39,13 @@ The compilation stops while compiling Kokkos with ``/usr/include/stdlib.h(58): e When using the Intel compiler on a Mac Intel, I get a linking error involving the ``SharedAllocationRecordIvvE18t_tracking_enabledE`` symbol. This is a known bug of the Intel Mac compiler with Kokkos. Apparently Intel has decided not to fix it. Check the issue on the `Kokkos git page `_. +I get an error during *Idefix* link that says there are undefined symbols to std::filesystem + This is a known bug/limitation of the stdlibc++ provided with gcc8 that does not include C++17 filesystem extensions. + While *Idefix* auto-detects gcc8 when it is used as the main compiler, it still misses the cases when another compiler + (like Clang or Intel) is used with gcc8 as a backend. + You should try to clear up CMakeCache.txt and explicitely add the required link library when calling cmake as in + ``LDFLAGS=-lstdc++fs cmake $IDEFIX_DIR ...``` + Execution --------- diff --git a/src/output/dump.cpp b/src/output/dump.cpp index 9bd10164..f52d00a1 100644 --- a/src/output/dump.cpp +++ b/src/output/dump.cpp @@ -6,7 +6,15 @@ // *********************************************************************************** #include -#include +#if __has_include() + #include + namespace fs = std::filesystem; +#elif __has_include() + #include + namespace fs = std::experimental::filesystem; +#else + error "Missing the header." +#endif #include #include "dump.hpp" #include "version.hpp" @@ -63,9 +71,9 @@ void Dump::Init(DataBlock *datain) { this->dumpFileNumber = 0; if(idfx::prank==0) { - if(!std::filesystem::is_directory(outputDirectory)) { + if(!fs::is_directory(outputDirectory)) { try { - if(!std::filesystem::create_directory(outputDirectory)) { + if(!fs::create_directory(outputDirectory)) { std::stringstream msg; msg << "Cannot create directory " << outputDirectory << std::endl; IDEFIX_ERROR(msg); @@ -524,7 +532,7 @@ void Dump::ReadDistributed(IdfxFileHandler fileHdl, int ndim, int *dim, int *gdi // Helper function to convert filesystem::file_time into std::time_t // see https://stackoverflow.com/questions/56788745/ // This conversion "hack" is required in C++17 as no proper conversion bewteen -// std::filesystem::last_write_time and std::time_t +// fs::last_write_time and std::time_t // exists in the standard library until C++20 template std::time_t to_time_t(TP tp) { @@ -533,15 +541,15 @@ std::time_t to_time_t(TP tp) { return std::chrono::system_clock::to_time_t(sctp); } -int Dump::GetLastDumpInDirectory(std::filesystem::path &directory) { +int Dump::GetLastDumpInDirectory(fs::path &directory) { int num = -1; std::time_t youngFileTime; bool first = true; - for (const auto & entry : std::filesystem::directory_iterator(directory)) { + for (const auto & entry : fs::directory_iterator(directory)) { // Check file extension if(entry.path().extension().string().compare(".dmp")==0) { - auto fileTime = to_time_t(std::filesystem::last_write_time(entry.path())); + auto fileTime = to_time_t(fs::last_write_time(entry.path())); // Check which one is the most recent if(first || fileTime>youngFileTime) { // std::tm *gmt = std::gmtime(&fileTime); @@ -563,7 +571,7 @@ int Dump::GetLastDumpInDirectory(std::filesystem::path &directory) { return(num); } bool Dump::Read(Output& output, int readNumber ) { - std::filesystem::path filename; + fs::path filename; int nx[3]; int nxglob[3]; std::string fieldName; @@ -574,7 +582,7 @@ bool Dump::Read(Output& output, int readNumber ) { idfx::pushRegion("Dump::Read"); - std::filesystem::path readDir = this->outputDirectory; + fs::path readDir = this->outputDirectory; if(readNumber<0) { // We actually don't know which file we're supposed to read, so let's guess @@ -746,7 +754,7 @@ bool Dump::Read(Output& output, int readNumber ) { int Dump::Write(Output& output) { - std::filesystem::path filename; + fs::path filename; char fieldName[NAMESIZE+1]; // +1 is just in case int nx[3]; int nxtot[3]; @@ -776,8 +784,8 @@ int Dump::Write(Output& output) { // Check if file exists, if yes, delete it if(idfx::prank==0) { - if(std::filesystem::exists(filename)) { - std::filesystem::remove(filename); + if(fs::exists(filename)) { + fs::remove(filename); } } diff --git a/src/output/dump.hpp b/src/output/dump.hpp index 657c9ed0..f324652d 100644 --- a/src/output/dump.hpp +++ b/src/output/dump.hpp @@ -9,8 +9,15 @@ #define OUTPUT_DUMP_HPP_ #include #include -#include - +#if __has_include() + #include + namespace fs = std::filesystem; +#elif __has_include() + #include + namespace fs = std::experimental::filesystem; +#else + error "Missing the header." +#endif #include "idefix.hpp" #include "input.hpp" #include "dataBlock.hpp" @@ -232,9 +239,9 @@ class Dump { void ReadSerial(IdfxFileHandler, int, int*, DataType, void*); void ReadDistributed(IdfxFileHandler, int, int*, int*, IdfxDataDescriptor&, void*); void Skip(IdfxFileHandler, int, int *, DataType); - int GetLastDumpInDirectory(std::filesystem::path &); + int GetLastDumpInDirectory(fs::path &); - std::filesystem::path outputDirectory; + fs::path outputDirectory; }; diff --git a/src/output/vtk.cpp b/src/output/vtk.cpp index 85401e3f..1c24823c 100644 --- a/src/output/vtk.cpp +++ b/src/output/vtk.cpp @@ -8,7 +8,15 @@ #include #include #include -#include +#if __has_include() + #include + namespace fs = std::filesystem; +#elif __has_include() + #include + namespace fs = std::experimental::filesystem; +#else + error "Missing the header." +#endif #include "vtk.hpp" #include "version.hpp" #include "idefix.hpp" @@ -64,9 +72,9 @@ Vtk::Vtk(Input &input, DataBlock *datain, std::string filebase) { } if(idfx::prank==0) { - if(!std::filesystem::is_directory(outputDirectory)) { + if(!fs::is_directory(outputDirectory)) { try { - if(!std::filesystem::create_directory(outputDirectory)) { + if(!fs::create_directory(outputDirectory)) { std::stringstream msg; msg << "Cannot create directory " << outputDirectory << std::endl; IDEFIX_ERROR(msg); @@ -247,7 +255,7 @@ int Vtk::Write() { idfx::pushRegion("Vtk::Write"); IdfxFileHandler fileHdl; - std::filesystem::path filename; + fs::path filename; timer.reset(); @@ -260,8 +268,8 @@ int Vtk::Write() { // Check if file exists, if yes, delete it if(this->isRoot) { - if(std::filesystem::exists(filename)) { - std::filesystem::remove(filename); + if(fs::exists(filename)) { + fs::remove(filename); } } diff --git a/src/output/vtk.hpp b/src/output/vtk.hpp index eb6b813f..be42f058 100644 --- a/src/output/vtk.hpp +++ b/src/output/vtk.hpp @@ -9,7 +9,15 @@ #define OUTPUT_VTK_HPP_ #include #include -#include +#if __has_include() + #include + namespace fs = std::filesystem; +#elif __has_include() + #include + namespace fs = std::experimental::filesystem; +#else + error "Missing the header." +#endif #include "idefix.hpp" #include "input.hpp" #include "dataBlock.hpp" @@ -158,7 +166,7 @@ class Vtk : public BaseVtk { void WriteHeaderNodes(IdfxFileHandler); // output directory - std::filesystem::path outputDirectory; + fs::path outputDirectory; }; template