fatal error: 'charconv' file not found in clang 6.0 with -std=c++17
Asked Answered
S

2

9

Recently, I wanted to use from_chars from c++17. Looked at http://en.cppreference.com/w/cpp/utility/from_chars and found that code on this page:

#include <iostream>
#include <charconv>
#include <array>

int main()
{
    std::array<char, 10> str{"42"};
    int result;
    std::from_chars(str.data(), str.data()+str.size(), result);
    std::cout << result;
}

cannot be compiled by any of compilers. I tried on page http://en.cppreference.com/w/cpp/utility/from_chars and on godbolt with different compilers but all of them returned the same error:

<source>:2:10: fatal error: 'charconv' file not found
#include <charconv>
         ^~~~~~~~~~
1 error generated.
Compiler returned: 1

Can anybody help me with this, please?

(I tried clang 6.0, gcc 7.3 and msvc 19 but all of them returned error that 'charconv' not found)

Selfsustaining answered 3/4, 2018 at 22:5 Comment(4)
charconv is a new file added to libstdc++ on 2 Oct 2017, as shown in gcc.gnu.org/ml/libstdc++/2017-10/msg00001.html. you need to update your libstdc++ firstly.Eveleen
@Eveleen do you know if MSVC supports it in last releases?Selfsustaining
I do not whether MSVC supports it or not, I think you need check its release note.Eveleen
please see this page: blogs.msdn.microsoft.com/vcblog/2017/12/19/…Eveleen
B
6

According to GCC's libstdc++ status page, this header is only supported starting from GCC-8.1. You could either avoid using this header by detecting it:

#if __has_include(<charconv>)
#include <charconv>
#else
/* implement some fallback */
#endif

Or just update your compiler. This godbolt example confirms that the header is present in GCC-8.1.

If you use Clang, remember that Clang uses GCC's stdlibc++ by default. You will either need to update your GCC or switch to Clang's libc++ by:

clang++ -std=c++17 -stdlib=libc++ main.cpp
Brockway answered 28/9, 2020 at 15:0 Comment(1)
I tried using both g++ and clang++ after getting them both updated. g++ is 8.4 and clang++ is 10.0. I tried with -stdlib=stdlibc++, stdlib=libc++ and nothing just in case. Then I enabled backports and pre-release and tried again. (I made sure g++, /usr/bin/g++, etc. pointed to the new versions.) I don't know what's left. Every time I switch to libc++ it stops finding anything at all.Sweitzer
P
0

update gcc version to 8.3, seems like an older gcc version causing problems

Poundage answered 24/12, 2022 at 13:22 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.