issue with iconv() on macOS using "WCHAR_T//TRANSLIT"

Hello,

I am working on a cross‑platform application that uses libiconv to convert strings to/from Unicode. I need to modify the existing code for compatibility with macOS. However, the call to iconv() fails with an unclear errno value (92) when using "WCHAR_T":

std::wstring ConvertToWchar(const std::string& iconvCodeSet, const std::string_view str)
{
    iconv_t conv = iconv_open("WCHAR_T//TRANSLIT", iconvCodeSet.c_str());

    if (conv == (iconv_t)-1)
    {
        std::cerr << "iconv_open() failed" << std::endl;
        return {};
    }

    std::wstring out(str.size(), L'\0');

    auto inPtr = (char*)str.data();
    size_t inSize = str.size();

    auto outPtr = (char*)out.data();
    size_t outSize = out.size() * sizeof(wchar_t);

    if (iconv(conv, &inPtr, &inSize, &outPtr, &outSize) == (size_t)-1)
    {
        std::cerr << "iconv() failed. errno = " << errno << std::endl;
        return {};
    }

    if (iconv(conv, nullptr, &inSize, &outPtr, &outSize) == (size_t)-1)
    {
        std::cerr << "iconv() failed. errno = " << errno << std::endl;
        return {};
    }

    iconv_close(conv);
    return out;
}

int main()
{
    std::string str1((const char*)u8"ΟΔΥΣΣΕΥΣ");
    std::wstring str2 = ConvertToWchar("UTF-8", str1);

    if (str2.empty())
        return 1;

    std::cout << "converted" << std::endl;
    return 0;
}

Using "UTF-32" works fine, but "WCHAR_T//TRANSLIT" fails.

What is the recommended way to convert wchar_t strings using libiconv?

Why does the conversion fail with "WCHAR_T//TRANSLIT"?

Thank you in advance!

issue with iconv() on macOS using "WCHAR_T//TRANSLIT"
 
 
Q