Skip to content

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

Closed
@miikka75

Description

@miikka75

What is the issue you have?

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 describe the steps to reproduce the issue.

GCC 7.5.0 declares: __cplusplus = 201703L, thus JSON_HAS_CPP_17 flag is set but in fact GCCv7 implements <experimental/filesystem>
https://stackoverflow.com/questions/45867379/why-does-gcc-not-seem-to-have-the-filesystem-standard-library

Can you provide a small but working code example?

See diff (to test project's CMakeLists.txt) at the end of bug report.

What is the expected behavior?

Compilation of json.hpp should work with GCCv7 with --std=c++17 compiler option.

And what is the actual behavior instead?

Compilation using GCCv7 outputs errors:

json-src/single_include/nlohmann/json.hpp:3954:14: fatal error: filesystem: No such file or directory
      #include <filesystem>

json-src/single_include/nlohmann/json.hpp:4384:45: error: ‘std::filesystem’ has not been declared
  void from_json(const BasicJsonType& j, std::filesystem::path& p)

Which compiler and operating system are you using?

  • Compiler: GCC v7.5.0
  • Operating system: Ubuntu 18.04

Which version of the library did you use?

  • latest release version 3.10.4
  • other release - please state the version: ___
  • the develop branch

If you experience a compilation error: can you compile and run the unit tests?

  • yes
  • no - please copy/paste the error message below

Compilation fails, if I make following change:

diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt
index 447192c..c63ef61 100644
--- a/test/CMakeLists.txt
+++ b/test/CMakeLists.txt
@@ -60,6 +60,7 @@ foreach(file ${files})
 
     add_executable(${testcase} $<TARGET_OBJECTS:doctest_main> ${file})
     target_compile_definitions(${testcase} PRIVATE DOCTEST_CONFIG_SUPER_FAST_ASSERTS)
+    set_property(TARGET ${testcase} PROPERTY CXX_STANDARD 17)
     target_compile_options(${testcase} PRIVATE
         $<$<CXX_COMPILER_ID:MSVC>:/EHsc;$<$<CONFIG:Release>:/Od>>
         $<$<NOT:$<CXX_COMPILER_ID:MSVC>>:-Wno-deprecated;-Wno-float-equal>

Metadata

Metadata

Assignees

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions