nlohmann / json

JSON for Modern C++
https://json.nlohmann.me
MIT License
43.21k stars 6.74k forks source link

JSON build fails for C++ cmake #3256

Closed alexandraBara closed 2 years ago

alexandraBara commented 2 years ago

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?

``` Downloading https://github.com/nlohmann/json/archive/HEAD.tar.gz -- [download 100% complete] -- The CXX compiler identification is Clang 13.0.0 -- Check for working CXX compiler: /opt/rocm/llvm/bin/clang++ -- Check for working CXX compiler: /opt/rocm/llvm/bin/clang++ -- works -- Detecting CXX compiler ABI info -- Detecting CXX compiler ABI info - done -- Detecting CXX compile features -- Detecting CXX compile features - done -- Using the single-header code from /tmp/cget-16-46-27-gKybD-1/download/json-6d8d043adde8c95589f6e65e1fe228cb1f0d8419/single_include/ -- Found Git: /usr/bin/git (found version "2.17.1") -- Operating system: Linux-4.15.0-163-generic; Distributor ID: Ubuntu; Description: Ubuntu 18.04.6 LTS; Release: 18.04; Codename: bionic; Linux 9e0027017371 4.15.0-163-generic #171-Ubuntu SMP Fri Nov 5 11:55:11 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux -- Compiler: AMD clang version 13.0.0 (https://github.com/RadeonOpenCompute/llvm-project roc-4.5.0 21422 e2489b0d7ede612d6586c61728db321047833ed8); Target: x86_64-unknown-linux-gnu; Thread model: posix; InstalledDir: /opt/rocm/llvm/bin -- Configuring done -- Generating done CMake Warning: Manually-specified variables were not used by the project: CGET_CMAKE_ORIGINAL_SOURCE_FILE -- Build files have been written to: /tmp/cget-16-46-27-gKybD-1/build Scanning dependencies of target doctest_main [ 0%] Building CXX object test/CMakeFiles/doctest_main.dir/src/unit.cpp.o [ 0%] Built target doctest_main Scanning dependencies of target test-wstring [ 1%] Building CXX object test/CMakeFiles/test-wstring.dir/src/unit-wstring.cpp.o Scanning dependencies of target test-ordered_map Scanning dependencies of target test-regression2 Scanning dependencies of target test-unicode1 Scanning dependencies of target test-element_access2 Scanning dependencies of target test-allocator Scanning dependencies of target test-serialization Scanning dependencies of target test-items Scanning dependencies of target test-diagnostics Scanning dependencies of target test-readme Scanning dependencies of target test-assert_macro Scanning dependencies of target test-deserialization Scanning dependencies of target test-disabled_exceptions Scanning dependencies of target test-msgpack Scanning dependencies of target test-algorithms Scanning dependencies of target test-hash Scanning dependencies of target test-alt-string Scanning dependencies of target test-element_access1 Scanning dependencies of target test-testsuites Scanning dependencies of target test-class_iterator Scanning dependencies of target test-cbor Scanning dependencies of target test-constructor1 Scanning dependencies of target test-constructor2 Scanning dependencies of target test-regression2_cpp17 Scanning dependencies of target test-conversions Scanning dependencies of target test-conversions_cpp17 Scanning dependencies of target test-udt_macro Scanning dependencies of target test-convenience Scanning dependencies of target test-modifiers Scanning dependencies of target test-unicode5 Scanning dependencies of target test-pointer_access Scanning dependencies of target test-ordered_json Scanning dependencies of target test-noexcept Scanning dependencies of target test-to_chars Scanning dependencies of target test-class_const_iterator Scanning dependencies of target test-items_cpp17 Scanning dependencies of target test-reference_access Scanning dependencies of target test-comparison Scanning dependencies of target test-ubjson Scanning dependencies of target test-bson Scanning dependencies of target test-byte_container_with_subtype Scanning dependencies of target test-capacity Scanning dependencies of target test-class_lexer Scanning dependencies of target test-regression1 Scanning dependencies of target test-udt Scanning dependencies of target test-json_patch Scanning dependencies of target test-user_defined_input Scanning dependencies of target test-iterators2 Scanning dependencies of target test-unicode3 [ 4%] Building CXX object test/CMakeFiles/test-regression2.dir/src/unit-regression2.cpp.o [ 4%] Building CXX object test/CMakeFiles/test-ordered_map.dir/src/unit-ordered_map.cpp.o Scanning dependencies of target test-class_parser Scanning dependencies of target test-regression1_cpp17 [ 5%] Building CXX object test/CMakeFiles/test-allocator.dir/src/unit-allocator.cpp.o [ 6%] Building CXX object test/CMakeFiles/test-element_access2.dir/src/unit-element_access2.cpp.o Scanning dependencies of target test-unicode2 [ 9%] Building CXX object test/CMakeFiles/test-deserialization.dir/src/unit-deserialization.cpp.o [ 9%] Building CXX object test/CMakeFiles/test-class_iterator.dir/src/unit-class_iterator.cpp.o [ 7%] Building CXX object test/CMakeFiles/test-readme.dir/src/unit-readme.cpp.o [ 9%] Building CXX object test/CMakeFiles/test-serialization.dir/src/unit-serialization.cpp.o [ 10%] Building CXX object test/CMakeFiles/test-constructor1.dir/src/unit-constructor1.cpp.o [ 10%] Building CXX object test/CMakeFiles/test-regression2_cpp17.dir/src/unit-regression2.cpp.o [ 11%] Building CXX object test/CMakeFiles/test-alt-string.dir/src/unit-alt-string.cpp.o Scanning dependencies of target test-meta [ 12%] Building CXX object test/CMakeFiles/test-algorithms.dir/src/unit-algorithms.cpp.o [ 13%] Building CXX object test/CMakeFiles/test-hash.dir/src/unit-hash.cpp.o [ 16%] Building CXX object test/CMakeFiles/test-element_access1.dir/src/unit-element_access1.cpp.o [ 16%] Building CXX object test/CMakeFiles/test-items.dir/src/unit-items.cpp.o [ 16%] Building CXX object test/CMakeFiles/test-disabled_exceptions.dir/src/unit-disabled_exceptions.cpp.o Scanning dependencies of target test-iterators1 Scanning dependencies of target test-inspection Scanning dependencies of target test-concepts [ 17%] Building CXX object test/CMakeFiles/test-conversions.dir/src/unit-conversions.cpp.o [ 17%] Building CXX object test/CMakeFiles/test-constructor2.dir/src/unit-constructor2.cpp.o Scanning dependencies of target test-large_json Scanning dependencies of target test-merge_patch Scanning dependencies of target test-json_pointer Scanning dependencies of target test-unicode4 [ 18%] Building CXX object test/CMakeFiles/test-diagnostics.dir/src/unit-diagnostics.cpp.o [ 18%] Building CXX object test/CMakeFiles/test-conversions_cpp17.dir/src/unit-conversions.cpp.o [ 19%] Building CXX object test/CMakeFiles/test-assert_macro.dir/src/unit-assert_macro.cpp.o [ 20%] Building CXX object test/CMakeFiles/test-msgpack.dir/src/unit-msgpack.cpp.o [ 20%] Building CXX object test/CMakeFiles/test-cbor.dir/src/unit-cbor.cpp.o [ 21%] Building CXX object test/CMakeFiles/test-testsuites.dir/src/unit-testsuites.cpp.o [ 22%] Building CXX object test/CMakeFiles/test-unicode1.dir/src/unit-unicode1.cpp.o [ 22%] Building CXX object test/CMakeFiles/test-unicode5.dir/src/unit-unicode5.cpp.o [ 23%] Building CXX object test/CMakeFiles/test-user_defined_input.dir/src/unit-user_defined_input.cpp.o [ 23%] Building CXX object test/CMakeFiles/test-regression1.dir/src/unit-regression1.cpp.o [ 23%] Building CXX object test/CMakeFiles/test-modifiers.dir/src/unit-modifiers.cpp.o [ 25%] Building CXX object test/CMakeFiles/test-pointer_access.dir/src/unit-pointer_access.cpp.o [ 24%] Building CXX object test/CMakeFiles/test-udt_macro.dir/src/unit-udt_macro.cpp.o [ 26%] Building CXX object test/CMakeFiles/test-ordered_json.dir/src/unit-ordered_json.cpp.o [ 27%] Building CXX object test/CMakeFiles/test-items_cpp17.dir/src/unit-items.cpp.o [ 28%] Building CXX object test/CMakeFiles/test-regression1_cpp17.dir/src/unit-regression1.cpp.o [ 29%] Building CXX object test/CMakeFiles/test-bson.dir/src/unit-bson.cpp.o [ 30%] Building CXX object test/CMakeFiles/test-noexcept.dir/src/unit-noexcept.cpp.o [ 31%] Building CXX object test/CMakeFiles/test-class_parser.dir/src/unit-class_parser.cpp.o [ 32%] Building CXX object test/CMakeFiles/test-meta.dir/src/unit-meta.cpp.o [ 32%] Building CXX object test/CMakeFiles/test-unicode2.dir/src/unit-unicode2.cpp.o [ 33%] Building CXX object test/CMakeFiles/test-byte_container_with_subtype.dir/src/unit-byte_container_with_subtype.cpp.o [ 34%] Building CXX object test/CMakeFiles/test-class_lexer.dir/src/unit-class_lexer.cpp.o [ 34%] Building CXX object test/CMakeFiles/test-json_pointer.dir/src/unit-json_pointer.cpp.o [ 35%] Building CXX object test/CMakeFiles/test-reference_access.dir/src/unit-reference_access.cpp.o [ 36%] Building CXX object test/CMakeFiles/test-class_const_iterator.dir/src/unit-class_const_iterator.cpp.o [ 41%] Building CXX object test/CMakeFiles/test-convenience.dir/src/unit-convenience.cpp.o [ 42%] Building CXX object test/CMakeFiles/test-comparison.dir/src/unit-comparison.cpp.o [ 41%] Building CXX object test/CMakeFiles/test-unicode3.dir/src/unit-unicode3.cpp.o [ 41%] Building CXX object test/CMakeFiles/test-udt.dir/src/unit-udt.cpp.o [ 41%] Building CXX object test/CMakeFiles/test-to_chars.dir/src/unit-to_chars.cpp.o [ 42%] Building CXX object test/CMakeFiles/test-ubjson.dir/src/unit-ubjson.cpp.o [ 43%] Building CXX object test/CMakeFiles/test-large_json.dir/src/unit-large_json.cpp.o [ 43%] Building CXX object test/CMakeFiles/test-merge_patch.dir/src/unit-merge_patch.cpp.o [ 44%] Building CXX object test/CMakeFiles/test-json_patch.dir/src/unit-json_patch.cpp.o [ 45%] Building CXX object test/CMakeFiles/test-iterators1.dir/src/unit-iterators1.cpp.o [ 46%] Building CXX object test/CMakeFiles/test-capacity.dir/src/unit-capacity.cpp.o [ 47%] Building CXX object test/CMakeFiles/test-unicode4.dir/src/unit-unicode4.cpp.o [ 48%] Building CXX object test/CMakeFiles/test-concepts.dir/src/unit-concepts.cpp.o [ 50%] Building CXX object test/CMakeFiles/test-iterators2.dir/src/unit-iterators2.cpp.o [ 50%] Building CXX object test/CMakeFiles/test-inspection.dir/src/unit-inspection.cpp.o [ 50%] Linking CXX executable test-noexcept [ 50%] Built target test-noexcept [ 51%] Linking CXX executable test-byte_container_with_subtype [ 52%] Linking CXX executable test-assert_macro [ 53%] Linking CXX executable test-class_lexer [ 53%] Built target test-byte_container_with_subtype [ 54%] Linking CXX executable test-large_json [ 54%] Built target test-assert_macro [ 54%] Built target test-class_lexer [ 54%] Built target test-large_json [ 55%] Linking CXX executable test-to_chars [ 56%] Linking CXX executable test-ordered_map [ 56%] Built target test-to_chars [ 57%] Linking CXX executable test-unicode4 [ 58%] Linking CXX executable test-wstring [ 58%] Built target test-ordered_map [ 58%] Built target test-unicode4 [ 58%] Built target test-wstring [ 59%] Linking CXX executable test-concepts [ 60%] Linking CXX executable test-convenience [ 61%] Linking CXX executable test-disabled_exceptions [ 62%] Linking CXX executable test-unicode2 [ 62%] Built target test-concepts [ 62%] Built target test-disabled_exceptions [ 62%] Built target test-convenience [ 62%] Built target test-unicode2 [ 63%] Linking CXX executable test-unicode3 [ 63%] Linking CXX executable test-constructor2 [ 63%] Built target test-unicode3 [ 63%] Built target test-constructor2 [ 64%] Linking CXX executable test-capacity [ 65%] Linking CXX executable test-unicode1 [ 65%] Built target test-capacity [ 66%] Linking CXX executable test-unicode5 [ 66%] Built target test-unicode1 [ 66%] Built target test-unicode5 [ 67%] Linking CXX executable test-class_iterator [ 67%] Built target test-class_iterator [ 68%] Linking CXX executable test-hash [ 69%] Linking CXX executable test-class_const_iterator [ 70%] Linking CXX executable test-diagnostics [ 70%] Built target test-hash [ 71%] Linking CXX executable test-user_defined_input [ 71%] Built target test-class_const_iterator [ 71%] Built target test-diagnostics [ 71%] Linking CXX executable test-allocator [ 71%] Built target test-user_defined_input [ 71%] Linking CXX executable test-items [ 72%] Linking CXX executable test-merge_patch [ 72%] Built target test-allocator [ 73%] Linking CXX executable test-reference_access [ 73%] Built target test-items [ 74%] Linking CXX executable test-serialization [ 74%] Built target test-merge_patch [ 74%] Built target test-reference_access [ 75%] Linking CXX executable test-meta [ 75%] Built target test-serialization [ 76%] Linking CXX executable test-algorithms [ 76%] Built target test-meta [ 76%] Built target test-algorithms [ 77%] Linking CXX executable test-alt-string [ 77%] Linking CXX executable test-testsuites [ 77%] Built target test-alt-string [ 78%] Linking CXX executable test-ordered_json [ 78%] Built target test-testsuites [ 78%] Linking CXX executable test-pointer_access [ 78%] Built target test-ordered_json [ 78%] Built target test-pointer_access [ 79%] Linking CXX executable test-inspection [ 79%] Linking CXX executable test-comparison [ 80%] Linking CXX executable test-json_pointer [ 80%] Built target test-inspection [ 80%] Built target test-comparison [ 81%] Linking CXX executable test-iterators1 [ 81%] Built target test-json_pointer [ 81%] Built target test-iterators1 [ 81%] Linking CXX executable test-iterators2 [ 83%] Linking CXX executable test-items_cpp17 [ 83%] Linking CXX executable test-json_patch [ 84%] Linking CXX executable test-element_access1 [ 85%] Linking CXX executable test-udt_macro [ 86%] Linking CXX executable test-modifiers [ 86%] Built target test-modifiers [ 86%] Built target test-element_access1 [ 86%] Built target test-items_cpp17 [ 86%] Built target test-udt_macro [ 86%] Built target test-iterators2 [ 86%] Built target test-json_patch [ 87%] Linking CXX executable test-class_parser [ 87%] Linking CXX executable test-bson [ 87%] Linking CXX executable test-element_access2 [ 87%] Built target test-class_parser [ 87%] Built target test-bson [ 87%] Built target test-element_access2 [ 88%] Linking CXX executable test-readme [ 88%] Built target test-readme [ 89%] Linking CXX executable test-msgpack [ 89%] Built target test-msgpack [ 90%] Linking CXX executable test-ubjson [ 90%] Built target test-ubjson [ 90%] Linking CXX executable test-udt [ 90%] Built target test-udt [ 91%] Linking CXX executable test-cbor [ 91%] Built target test-cbor [ 92%] Linking CXX executable test-constructor1 [ 92%] Built target test-constructor1 [ 93%] Linking CXX executable test-regression2 [ 93%] Built target test-regression2 [ 94%] Linking CXX executable test-deserialization [ 94%] Built target test-deserialization [ 95%] Linking CXX executable test-conversions [ 96%] Linking CXX executable test-regression2_cpp17 ld.lld: error: undefined symbol: std::experimental::filesystem::v1::__cxx11::path::_M_split_cmpts() >>> referenced by unit-regression2.cpp >>> CMakeFiles/test-regression2_cpp17.dir/src/unit-regression2.cpp.o:(std::experimental::filesystem::v1::__cxx11::path::path(char const (&) [14])) >>> referenced by unit-regression2.cpp >>> CMakeFiles/test-regression2_cpp17.dir/src/unit-regression2.cpp.o:(std::experimental::filesystem::v1::__cxx11::path::path, std::allocator >, std::experimental::filesystem::v1::__cxx11::path>(std::__cxx11::basic_string, std::allocator > const&)) >>> referenced by unit-regression2.cpp >>> CMakeFiles/test-regression2_cpp17.dir/src/unit-regression2.cpp.o:(std::experimental::filesystem::v1::__cxx11::path::clear()) ld.lld: error: undefined symbol: std::experimental::filesystem::v1::__cxx11::path::compare(std::experimental::filesystem::v1::__cxx11::path const&) const >>> referenced by unit-regression2.cpp >>> CMakeFiles/test-regression2_cpp17.dir/src/unit-regression2.cpp.o:(std::experimental::filesystem::v1::__cxx11::operator==(std::experimental::filesystem::v1::__cxx11::path const&, std::experimental::filesystem::v1::__cxx11::path const&)) clang-13: error: linker command failed with exit code 1 (use -v to see invocation) test/CMakeFiles/test-regression2_cpp17.dir/build.make:85: recipe for target 'test/test-regression2_cpp17' failed make[2]: *** [test/test-regression2_cpp17] Error 1 make[1]: *** [test/CMakeFiles/test-regression2_cpp17.dir/all] Error 2 make[1]: *** Waiting for unfinished jobs.... CMakeFiles/Makefile2:2065: recipe for target 'test/CMakeFiles/test-regression2_cpp17.dir/all' failed [ 96%] Built target test-conversions [ 97%] Linking CXX executable test-conversions_cpp17 [ 97%] Built target test-conversions_cpp17 [ 98%] Linking CXX executable test-regression1 [ 98%] Built target test-regression1 [100%] Linking CXX executable test-regression1_cpp17 [100%] Built target test-regression1_cpp17 Makefile:140: recipe for target 'all' failed make: *** [all] Error 2 CMake Error at /usr/local/share/cmake/cmakeget/CMakeGet.cmake:142 (message): Process failed: /usr/bin/cmake --build /tmp/cget-16-46-27-gKybD-1/build --config Release -- -j 128 Call Stack (most recent call first): /usr/local/share/cmake/cmakeget/CMakeGet.cmake:199 (cget_exec) /usr/local/share/cmake/cmakeget/CMakeGet.cmake:401 (cget_install_dir) /usr/local/share/cmake/cmakeget/CMakeGet.cmake:461 (cmake_get) install_deps.cmake:90 (cmake_get_from) ```

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?

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

nlohmann commented 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?

alexandraBara commented 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?

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.

nlohmann commented 2 years ago

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?

NicolasIRAGNE commented 2 years ago

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.

nlohmann commented 2 years ago

Can you please check the code from https://github.com/nlohmann/json/issues/3256#issuecomment-1007730993 and post what is detected for your compiler?

alexandraBara commented 2 years ago
  #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"

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 /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]

pragma message "JSON_HAS_EXPERIMENATL_F: " XSTR(JSON_HAS_EXPERIMENTAL_FILESYSTEM)

    ^

test.cpp:29:9: warning: JSON_HAS_FILESYSTEM: 0 [-W#pragma-messages]

pragma message "JSON_HAS_FILESYSTEM: " XSTR(JSON_HAS_FILESYSTEM)

    ^

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)

gregmarr commented 2 years ago

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

alexandraBara commented 2 years ago

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'

nlohmann commented 2 years ago

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?

alexandraBara commented 2 years ago

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?

That is correct, the library correctly detected the experimental/filesystem :). Please feel free to close this issue and thank you for helping out.

nlohmann commented 2 years ago

Thanks!

snorrikris commented 2 years ago

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:

define JSON_HAS_CPP_14

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.