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 #3090

Closed
2 of 5 tasks
miikka75 opened this issue Oct 18, 2021 · 10 comments · Fixed by #3101
Closed
2 of 5 tasks

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

miikka75 opened this issue Oct 18, 2021 · 10 comments · Fixed by #3101
Assignees
Labels
kind: bug release item: 🐛 bug fix solution: proposed fix a fix for the issue has been proposed and waits for confirmation

Comments

@miikka75
Copy link

miikka75 commented Oct 18, 2021

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>
@nlohmann
Copy link
Owner

Oh dear - it seems we forgot about compilers that did not implement the standard completely... We'll check.

@trailblazn
Copy link

Thank you, just ran into this myself!

@Llcoolsouder
Copy link

I am running into this same problem. If it's not already known, for some compilers (e.g. GCC 7.5) you have to do #include <experimental/filesystem>.

@nlohmann
Copy link
Owner

nlohmann commented Nov 1, 2021

I am running into this same problem. If it's not already known, for some compilers (e.g. GCC 7.5) you have to do #include <experimental/filesystem>.

Yes, this is what #3101 is doing. Unfortunately, there are still tests failing with Clang 9.

@Llcoolsouder
Copy link

I am running into this same problem. If it's not already known, for some compilers (e.g. GCC 7.5) you have to do #include <experimental/filesystem>.

Yes, this is what #3101 is doing. Unfortunately, there are still tests failing with Clang 9.

@nlohmann Yeah, I found that Issue after a little more digging. I plan on looking into it more today.

@Llcoolsouder
Copy link

@nlohmann
Copy link
Owner

nlohmann commented Nov 1, 2021

The detection of whether or not std::filesystem works is already realized in #3101. The remaining problem in #3101 is that Clang 9 (which does support std::filesystem) seems to choose the �wrong overload, see #3101 (comment).

@bobluoluo
Copy link

try using a guard

#if defined(_MSC_VER) && _MSC_VER < 1914
#include <experimental/filesystem>
#elif defined(__has_include)
#if __has_include()
#include
#elif __has_include(<experimental/filesystem>)
#include <experimental/filesystem>
#endif
#endif

@gregmarr
Copy link
Contributor

@bobluoluo That's already in #3101

SivaKesava1 added a commit to dns-groot/groot that referenced this issue Nov 11, 2021
- Ubuntu:18.04 has issues with c++17 and nlohmann_json (nlohmann/json#3090)
- Added dos2unix to fix  DOS line endings  to enable building in Windows
- Added CodeQL analysis
vadz added a commit to vadz/json that referenced this issue Dec 14, 2021
This can be useful when the compiler claims C++17 support, but standard
library std::filesystem implementation is unavailable (MinGW) or can't
be used because the current macOS target is too low to allow it (nlohmann#3156).

See nlohmann#3090.
chakpongchung added a commit to chakpongchung/katana that referenced this issue Dec 17, 2021
chakpongchung added a commit to KatanaGraph/katana that referenced this issue Dec 17, 2021
* upgrade the nlohmann_json from 3.7.3 to 3.10.4
to avoid variable conflict btw antlr-runtime 4.9.3 and nlohmann_json
due to underspecified EOF without namespace

After switching to the 4.9.3 runtime, encounter this conflict with our json parser. looking at it.
details below:
https://github.com/KatanaGraph/katana-enterprise/pull/2681#issuecomment-996016030

```
/root/.conan/data/nlohmann_json/3.7.3/_/_/package/5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9/include/nlohmann/detail/input/binary_reader.hpp:17:
2021-12-16T16:53:42.4746873Z �[1m/root/.conan/data/nlohmann_json/3.7.3/_/_/package/5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9/include/nlohmann/detail/input/input_adapters.hpp:117:20: �[0m�[0;1;31merror: �[0m�[1muse of undeclared identifier 'EOF'; did you mean 'XPathLexer::EOF'?�[0m
2021-12-16T16:53:42.4754024Z         if (res == EOF)
2021-12-16T16:53:42.4760480Z �[0;1;32m                   ^
2021-12-16T16:53:42.4768646Z �[0m�[1m/root/.conan/data/antlr4-cppruntime/4.9.3/_/_/package/ed4c50cce248f963b530d644f4c27bd3c33aa7ed/include/antlr4-runtime/Recognizer.h:16:29: �[0m�[0;1;30mnote: �[0m'XPathLexer::EOF' declared here�[0m
2021-12-16T16:53:42.4775961Z     static constexpr size_t EOF = std::numeric_limits<size_t>::max();
2021-12-16T16:53:42.4782322Z �[0;1;32m                            ^
2021-12-16T16:53:42.4787849Z �[0m1 error generated.
2021-12-16T16:53:42.4817761Z make[2]: *** [libquery/test/CMakeFiles/antlr-parser-test.dir/build.make:76: libquery/test/CMakeFiles/antlr-parser-test.dir/antlr-test.cpp.o] Error 1
2021-12-16T16:53:42.4829423Z make[1]: *** [CMakeFiles/Makefile2:8418: libquery/test/CMakeFiles/antlr-parser-test.dir/all] Error 2
```

https://github.com/nlohmann/json/blob/v3.7.3/include/nlohmann/detail/input/input_adapters.hpp#L117

Looks like it is fixed in latest(3.10.4) json parser:
https://github.com/nlohmann/json/blob/v3.10.4/include/nlohmann/detail/input/input_adapters.hpp#L112

* 3.10.4 has known unsolved issue:
nlohmann/json#3090
@nlohmann nlohmann added the solution: proposed fix a fix for the issue has been proposed and waits for confirmation label Dec 28, 2021
@nlohmann nlohmann self-assigned this Dec 28, 2021
@nlohmann nlohmann added this to the Release 3.10.5 milestone Dec 28, 2021
@niyunsheng
Copy link

Using stdc++fs add in target_link_libraries helps.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind: bug release item: 🐛 bug fix solution: proposed fix a fix for the issue has been proposed and waits for confirmation
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants