Closed alexandraBara closed 2 years ago
It seems that the compiler does not support std::filesystem
, or we do not properly detect the support.
Just to make sure: can you please check the latest release 3.10.5?
It seems that the compiler does not support
std::filesystem
, or we do not properly detect the support.Just to make sure: can you please check the latest release 3.10.5?
We are using clang 13 and this has std::filesystem support since I believe version 9. I specified version 3.10.5 and the same error persists.
We use Clang 13 in the CI without issues. 🤔
The error mention
std::experimental::filesystem::v1::__cxx11::path::_M_split_cmpts()
which makes no sense if the compiler has filesystem support. We use the following preprocessor checks:
#if defined(__cpp_lib_filesystem)
#define JSON_HAS_FILESYSTEM 1
#elif defined(__cpp_lib_experimental_filesystem)
#define JSON_HAS_EXPERIMENTAL_FILESYSTEM 1
#elif !defined(__has_include)
#define JSON_HAS_EXPERIMENTAL_FILESYSTEM 1
#elif __has_include(<filesystem>)
#define JSON_HAS_FILESYSTEM 1
#elif __has_include(<experimental/filesystem>)
#define JSON_HAS_EXPERIMENTAL_FILESYSTEM 1
#endif
#ifndef JSON_HAS_EXPERIMENTAL_FILESYSTEM
#define JSON_HAS_EXPERIMENTAL_FILESYSTEM 0
#endif
#ifndef JSON_HAS_FILESYSTEM
#define JSON_HAS_FILESYSTEM 0
#endif
Can you please execute this with your compiler in C++17 mode and check which values are set for JSON_HAS_FILESYSTEM
and JSON_HAS_EXPERIMENTAL_FILESYSTEM
?
Hello,
I do not think this error comes from json.
Your error mentions std::experimental::filesystem
which as far as I know, was the pre-standard implementation. With the following code:
#include <experimental/filesystem>
#include <iostream>
int main(int ac, char **av)
{
std::experimental::filesystem::path p(".");
std::experimental::filesystem::path p2("..");
std::cout << p.compare(p2) << std::endl;
}
I get the following errors:
➜ TestClang clang++-13 main.cpp -std=c++17
/usr/bin/ld: /tmp/main-13e873.o: in function `main':
main.cpp:(.text+0x42): undefined reference to `std::experimental::filesystem::v1::__cxx11::path::compare(std::experimental::filesystem::v1::__cxx11::path const&) const'
/usr/bin/ld: /tmp/main-13e873.o: in function `std::experimental::filesystem::v1::__cxx11::path::path<char [2], std::experimental::filesystem::v1::__cxx11::path>(char const (&) [2])':
main.cpp:(.text._ZNSt12experimental10filesystem2v17__cxx114pathC2IA2_cS3_EERKT_[_ZNSt12experimental10filesystem2v17__cxx114pathC2IA2_cS3_EERKT_]+0x55): undefined reference to `std::experimental::filesystem::v1::__cxx11::path::_M_split_cmpts()'
/usr/bin/ld: /tmp/main-13e873.o: in function `std::experimental::filesystem::v1::__cxx11::path::path<char [3], std::experimental::filesystem::v1::__cxx11::path>(char const (&) [3])':
main.cpp:(.text._ZNSt12experimental10filesystem2v17__cxx114pathC2IA3_cS3_EERKT_[_ZNSt12experimental10filesystem2v17__cxx114pathC2IA3_cS3_EERKT_]+0x55): undefined reference to `std::experimental::filesystem::v1::__cxx11::path::_M_split_cmpts()'
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Replacing std::experimental::filesystem with std::filesystem compiles with no issue.
Do you happen to use experimental/filesystem
in your code by any chance ?
Edit: I'm an idiot and didn't see that the code snippet that was posted is supposed to handle exactly what I said. Whoops. Sorry. It's still weird that it is trying to link with the experimental:: version however.
Can you please check the code from https://github.com/nlohmann/json/issues/3256#issuecomment-1007730993 and post what is detected for your compiler?
#if defined(__cpp_lib_filesystem) #define JSON_HAS_FILESYSTEM 1 #elif defined(__cpp_lib_experimental_filesystem) #define JSON_HAS_EXPERIMENTAL_FILESYSTEM 1 #elif !defined(__has_include) #define JSON_HAS_EXPERIMENTAL_FILESYSTEM 1 #elif __has_include(<filesystem>) #define JSON_HAS_FILESYSTEM 1 #elif __has_include(<experimental/filesystem>) #define JSON_HAS_EXPERIMENTAL_FILESYSTEM 1 #endif
I ran @NicolasIRAGNE code, here is the result: JSON_HAS_EXPERIMENATL_FILESYSTEM is 1 JSON_HAS_FILESYSTEM is 0
clang version 13.0.0 (https://github.com/RadeonOpenCompute/llvm-project roc-4.3.0 21295 f2943f684437d2c1143a56e418d29fc6b3314072) Target: x86_64-unknown-linux-gnu Thread model: posix InstalledDir: /opt/rocm/llvm/bin Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/7 Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/7.5.0 Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/8 Selected GCC installation: /usr/lib/gcc/x86_64-linux-gnu/7.5.0 Candidate multilib: .;@m64 Candidate multilib: 32;@m32 Candidate multilib: x32;@mx32 Selected multilib: .;@m64 Found HIP installation: /opt/rocm, version 4.3.21300-5bbc51d8 "/opt/rocm-4.3.0/llvm/bin/clang-13" -cc1 -triple x86_64-unknown-linux-gnu -emit-obj -mrelax-all --mrelax-relocations -disable-free -disable-llvm-verifier -discard-value-names -main-file-name test.cpp -mrelocation-model static -mframe-pointer=all -fmath-errno -fno-rounding-math -mconstructor-aliases -munwind-tables -target-cpu x86-64 -tune-cpu generic -fno-split-dwarf-inlining -debugger-tuning=gdb -v -resource-dir /opt/rocm-4.3.0/llvm/lib/clang/13.0.0 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/7.5.0/../../../../include/c++/7.5.0 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/7.5.0/../../../../include/x86_64-linux-gnu/c++/7.5.0 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/7.5.0/../../../../include/x86_64-linux-gnu/c++/7.5.0 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/7.5.0/../../../../include/c++/7.5.0/backward -internal-isystem /usr/local/include -internal-isystem /opt/rocm-4.3.0/llvm/lib/clang/13.0.0/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -Wall -std=c++17 -fdeprecated-macro -fdebug-compilation-dir=/home/fpadmin -ferror-limit 19 -fgnuc-version=4.2.1 -fcxx-exceptions -fexceptions -fcolor-diagnostics -faddrsig -o /tmp/test-f9b375.o -x c++ test.cpp clang -cc1 version 13.0.0 based upon LLVM 13.0.0git default target x86_64-unknown-linux-gnu ignoring nonexistent directory "/include" ignoring duplicate directory "/usr/lib/gcc/x86_64-linux-gnu/7.5.0/../../../../include/x86_64-linux-gnu/c++/7.5.0"
/usr/lib/gcc/x86_64-linux-gnu/7.5.0/../../../../include/c++/7.5.0 /usr/lib/gcc/x86_64-linux-gnu/7.5.0/../../../../include/x86_64-linux-gnu/c++/7.5.0 /usr/lib/gcc/x86_64-linux-gnu/7.5.0/../../../../include/c++/7.5.0/backward /usr/local/include /opt/rocm-4.3.0/llvm/lib/clang/13.0.0/include /usr/include/x86_64-linux-gnu /usr/include End of search list. test.cpp:28:9: warning: JSON_HAS_EXPERIMENATL_F: 1 [-W#pragma-messages]
^
test.cpp:29:9: warning: JSON_HAS_FILESYSTEM: 0 [-W#pragma-messages]
^
2 warnings generated. "/opt/rocm/llvm/bin/ld.lld" -z relro --hash-style=gnu --eh-frame-hdr -m elf_x86_64 -dynamic-linker /lib64/ld-linux-x86-64.so.2 -o a.out /usr/lib/gcc/x86_64-linux-gnu/7.5.0/../../../x86_64-linux-gnu/crt1.o /usr/lib/gcc/x86_64-linux-gnu/7.5.0/../../../x86_64-linux-gnu/crti.o /usr/lib/gcc/x86_64-linux-gnu/7.5.0/crtbegin.o -L/usr/lib/gcc/x86_64-linux-gnu/7.5.0 -L/usr/lib/gcc/x86_64-linux-gnu/7.5.0/../../../x86_64-linux-gnu -L/lib/x86_64-linux-gnu -L/lib/../lib64 -L/usr/lib/x86_64-linux-gnu -L/usr/lib/gcc/x86_64-linux-gnu/7.5.0/../../.. -L/opt/rocm-4.3.0/llvm/bin/../lib -L/lib -L/usr/lib /tmp/test-f9b375.o -lstdc++ -lm -lgcc_s -lgcc -lc -lgcc_s -lgcc /usr/lib/gcc/x86_64-linux-gnu/7.5.0/crtend.o /usr/lib/gcc/x86_64-linux-gnu/7.5.0/../../../x86_64-linux-gnu/crtn.o ld.lld: error: undefined symbol: std::experimental::filesystem::v1::cxx11::path::compare(std::experimental::filesystem::v1::cxx11::path const&) const
referenced by test.cpp /tmp/test-f9b375.o:(main)
ld.lld: error: undefined symbol: std::experimental::filesystem::v1::__cxx11::path::_M_split_cmpts()
referenced by test.cpp /tmp/test-f9b375.o:(std::experimental::filesystem::v1::cxx11::path::path<char [2], std::experimental::filesystem::v1::cxx11::path>(char const (&) [2])) referenced by test.cpp /tmp/test-f9b375.o:(std::experimental::filesystem::v1::cxx11::path::path<char [3], std::experimental::filesystem::v1::cxx11::path>(char const (&) [3])) clang-13: error: linker command failed with exit code 1 (use -v to see invocation)
Looks like it's somehow using the GCC 7.5.0 standard library instead of libc++.
/usr/lib/gcc/x86_64-linux-gnu/7.5.0/../../../../include/c++/7.5.0 /usr/lib/gcc/x86_64-linux-gnu/7.5.0/../../../../include/x86_64-linux-gnu/c++/7.5.0 /usr/lib/gcc/x86_64-linux-gnu/7.5.0/../../../../include/c++/7.5.0/backward
Looks like it's somehow using the GCC 7.5.0 standard library instead of libc++.
include "..." search starts here: #include <...> search starts here: /usr/lib/gcc/x86_64-linux-gnu/7.5.0/../../../../include/c++/7.5.0 /usr/lib/gcc/x86_64-linux-gnu/7.5.0/../../../../include/x86_64-linux-gnu/c++/7.5.0 /usr/lib/gcc/x86_64-linux-gnu/7.5.0/../../../../include/c++/7.5.0/backward
I think that is OK. I was able to run this code by adding the '-lstdc++fs'
So the library correctly detected that the used libc++ only supports <experimental/filesystem>
, but the CMake files for the test suite compilation did not link stdc++fs
, because it expected the compiler did not need it. Right?
So the library correctly detected that the used libc++ only supports
<experimental/filesystem>
, but the CMake files for the test suite compilation did not linkstdc++fs
, because it expected the compiler did not need it. Right?
That is correct, the library correctly detected the experimental/filesystem :). Please feel free to close this issue and thank you for helping out.
Thanks!
Unrelated maybe... But I had a strange issue when building release (x64) build in VS2022 v17.1.2 using c++20 (I'm playing with modules). Same project builds in Debug x64.
This is the error:
error LNK2001: unresolved external symbol "bool __cdecl std::filesystem::operator==(class std::filesystem::_Path_iterator<template-type-parameter-1'> const &,class std::filesystem::_Path_iterator<
template-type-parameter-1'> const &)" (??8filesystem@std@@YA_NAEBV?$_Path_iterator@$RBAAB@@01@0@Z)
I finally solved this by adding in json.hpp at line 54:
FYI - I have tried countless things before posting here. Including removing any code using std::filesystem. Nlohmann json is the only library using std::filesystem in my project, that's why I suspected a problem in the json code. I just though I should mention this in case others are having the same problem. But it would be nice to find a solution of course.
What is the issue you have?
I suspect recent changes in the library broke building JSON for C++. It worked up until a couple days ago. I have added a code snipped of the fail below.
Please describe the steps to reproduce the issue.
1. 2. 3.
Can you provide a small but working code example?
What is the expected behavior?
And what is the actual behavior instead?
Which compiler and operating system are you using?
Which version of the library did you use?
develop
branchIf you experience a compilation error: can you compile and run the unit tests?