Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GCC 7.5.0 with --std=c++17: filesystem: No such file or directory #79

Closed
ijulles opened this issue Apr 17, 2024 · 1 comment
Closed
Assignees
Labels
enhancement New feature or request

Comments

@ijulles
Copy link
Collaborator

ijulles commented Apr 17, 2024

Compilation fails using GCC 7.5.0 (default GCC compiler version in ubuntu 18.04) for a target which has --std=c++17 compiler option.

Please see: nlohmann/json#3090

I'd like to add a filesystem header file in include/mdf , add code like below from https://stackoverflow.com/questions/53365538/how-to-determine-whether-to-use-filesystem-or-experimental-filesystem

// We haven't checked which filesystem to include yet
#ifndef INCLUDE_STD_FILESYSTEM_EXPERIMENTAL

// Check for feature test macro for <filesystem>
#   if defined(__cpp_lib_filesystem)
#       define INCLUDE_STD_FILESYSTEM_EXPERIMENTAL 0

// Check for feature test macro for <experimental/filesystem>
#   elif defined(__cpp_lib_experimental_filesystem)
#       define INCLUDE_STD_FILESYSTEM_EXPERIMENTAL 1

// We can't check if headers exist...
// Let's assume experimental to be safe
#   elif !defined(__has_include)
#       define INCLUDE_STD_FILESYSTEM_EXPERIMENTAL 1

// Check if the header "<filesystem>" exists
#   elif __has_include(<filesystem>)

// If we're compiling on Visual Studio and are not compiling with C++17, we need to use experimental
#       ifdef _MSC_VER

// Check and include header that defines "_HAS_CXX17"
#           if __has_include(<yvals_core.h>)
#               include <yvals_core.h>

// Check for enabled C++17 support
#               if defined(_HAS_CXX17) && _HAS_CXX17
// We're using C++17, so let's use the normal version
#                   define INCLUDE_STD_FILESYSTEM_EXPERIMENTAL 0
#               endif
#           endif

// If the marco isn't defined yet, that means any of the other VS specific checks failed, so we need to use experimental
#           ifndef INCLUDE_STD_FILESYSTEM_EXPERIMENTAL
#               define INCLUDE_STD_FILESYSTEM_EXPERIMENTAL 1
#           endif

// Not on Visual Studio. Let's use the normal version
#       else // #ifdef _MSC_VER
#           define INCLUDE_STD_FILESYSTEM_EXPERIMENTAL 0
#       endif

// Check if the header "<filesystem>" exists
#   elif __has_include(<experimental/filesystem>)
#       define INCLUDE_STD_FILESYSTEM_EXPERIMENTAL 1

// Fail if neither header is available with a nice error message
#   else
#       error Could not find system header "<filesystem>" or "<experimental/filesystem>"
#   endif


// We priously determined that we need the exprimental version
#   if INCLUDE_STD_FILESYSTEM_EXPERIMENTAL
// Include it
#       include <experimental/filesystem>
        namespace fs = std::experimental::filesystem;
// We have a decent compiler and can use the normal version
#   else
// Include it
#       include <filesystem>
        namespace fs = std::filesystem;
#   endif

#endif // #ifndef INCLUDE_STD_FILESYSTEM_EXPERIMENTAL

Then replace #include<filesystem> with #include "mdf/filesystem.h", and use fs:: instead of std::filesystem::

What do you think about this?

If you think it's okay, I can create a PR to fix it.

@ihedvall
Copy link
Owner

This filesystem issue have been dealt with before. GCC implemented in GCC 8. The last time, it was solved by updating the GCC compiler but he was running in a Linux container. It's OK to do the change. There is already a src/platform.cpp and a src/platform.h file that deal with different compiler issues. It might be better to use that files. Just ensure that the include/.. files, not are affected i.e. the modified platform.h should only be in src/.. files.

@ihedvall ihedvall added the enhancement New feature or request label Apr 18, 2024
ihedvall added a commit that referenced this issue Apr 18, 2024
fix #79:include <experimental/filesystem> for old compilers
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Development

No branches or pull requests

2 participants