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

Function std::wstring s_2_ws(const std::string& s) needs to be declared inline to prevent GCC linking errors #75

Open
rost0031 opened this issue Apr 13, 2021 · 3 comments

Comments

@rost0031
Copy link

Windows 7, mingw (MSYS2)
gcc 10.2.0

in mio.hpp, line 798:

std::wstring s_2_ws(const std::string& s)
{
    if (s.empty())
        return{};
    const auto s_length = static_cast<int>(s.length());
    auto buf = std::vector<wchar_t>(s_length);
    const auto wide_char_count = MultiByteToWideChar(CP_UTF8, 0, s.c_str(), s_length, buf.data(), s_length);
    return std::wstring(buf.data(), wide_char_count);
}

The function above would compile with older versions for GCC (9.3.0 on kunbuntu 20.04) but fails to compile in above listed Windows7 environment with an error during linking:

multiple definition of  `mio::detail::win::s_2_ws(std::__cxx11:basic_string<char, std::char_traits<char>, std::allocator<char> > const &);

... 
first defined here

and it lists the same location in the hpp file.

The solution is simple: make the function s_2_ws inline. That gets rid of the error.

inline std::wstring s_2_ws(const std::string& s)
{
    if (s.empty())
        return{};
    const auto s_length = static_cast<int>(s.length());
    auto buf = std::vector<wchar_t>(s_length);
    const auto wide_char_count = MultiByteToWideChar(CP_UTF8, 0, s.c_str(), s_length, buf.data(), s_length);
    return std::wstring(buf.data(), wide_char_count);
}

The problem exists in both the single include as well as regular ipp file.

@cculianu
Copy link

I'm having the same issue also building with mingw gcc. Thanks for the tip on how to fix it.

@kerim371
Copy link

Thank you, the same error I got (on Windows though)

@Green-Sky
Copy link

fixed by #88

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants