Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Android: undefined reference on std::ostringstream. Why?



  • Hello all!
    I have this pice of code:

    std::ostringstream oStringStream;
    oStringStream << std::this_thread::get_id();
    std::string oThreadIDString = oStringStream.str();
    const char* oThreadID = oThreadIDString.c_str();
    

    It's working perfectly for iOS and MacOS but for Android I have this error:

    error: error: undefined reference to 'std::__ndk1::basic_ostream<char, std::__ndk1::char_traits<char> >& std::__ndk1::operator<< <char, std::__ndk1::char_traits<char> >(std::__ndk1::basic_ostream<char, std::__ndk1::char_traits<char> >&, std::__ndk1::__thread_id)'
    

    Why is that? What am I missing?



  • @bogong

    That is actually not Qt problem as it looks.

    Whatever the return value of get_id() is. Assign it to a variable and output this. My guess is that there is a different declaration which is actually different from standard types, but other compilers are not as "nervous".



  • Solution found.

    QString oThreadIDString = QString("0x%1");
    QString oThreadIDValue = oThreadIDString.arg((long)QThread::currentThread(),0,16);
    std::string oThreadIDStdString = oThreadIDValue.toStdString();
    

Log in to reply