3.10 - SetThreadDescription problem

classic Classic list List threaded Threaded
5 messages Options
VirtualSim VirtualSim
Reply | Threaded
Open this post in threaded view
|

3.10 - SetThreadDescription problem


As I am unable to compile the osgEarth 3.10 Core on OSG 3.6.5 (nor 3.4.0) using Windows SDK 10.0.14393

Threading.obj : error LNK2019: unresolved external symbol __imp__SetThreadDescription@8 referenced in function "void __cdecl osgEarth::Threading::setThreadName(...

I am wondering if I can just comment the line:
::SetThreadDescription(::GetCurrentThread(), buf);  
??
I can then BUILD ALL without problem and many examples I tested work fine.

So, what could be the side effect of this change and, if the function setThreadName is important, how to make it work ? (including kernel32.lib into the makefile does not solve it)

Thanks.
gwaldron gwaldron
Reply | Threaded
Open this post in threaded view
|

Re: 3.10 - SetThreadDescription problem

No side effects at all. It's just there to help with debugging.
Glenn Waldron / Pelican Mapping
jasonbeverage jasonbeverage
Reply | Threaded
Open this post in threaded view
|

Re: 3.10 - SetThreadDescription problem

In reply to this post by VirtualSim
So I ran into something like that before when trying to do builds on AppVeyor.  So if you are getting a linker error and not a compiler error that means SetThreadDescription is in the header but not getting linked.  It sounds like SetThreadDescription was added in the 1607 version of the  Windows SDK.  I've added a github issue to track it at https://github.com/gwaldron/osgearth/issues/1681.
VirtualSim VirtualSim
Reply | Threaded
Open this post in threaded view
|

Re: 3.10 - SetThreadDescription problem

In reply to this post by gwaldron
Thanks :-)
jasonbeverage jasonbeverage
Reply | Threaded
Open this post in threaded view
|

Re: 3.10 - SetThreadDescription problem

Can you do me a favor and try to compile with this code in osgEarth::Threading::setThreadName?

if (defined _WIN32 && defined _WIN32_WINNT_WIN10 && defined _WIN32_WINNT && _WIN32_WINNT >= _WIN32_WINNT_WIN10) || (defined __CYGWIN__)
    wchar_t buf[256];
    mbstowcs(buf, name.c_str(), 256);

    typedef ::HRESULT(WINAPI* SetThreadDescription)(::HANDLE hThread, ::PCWSTR lpThreadDescription);
    auto set_thread_description_func = reinterpret_cast<SetThreadDescription>(::GetProcAddress(::GetModuleHandle("Kernel32.dll"), "SetThreadDescription"));
    if (set_thread_description_func)
    {
        set_thread_description_func(::GetCurrentThread(), buf);
        return;
    }

#elif defined _GNU_SOURCE && !defined __EMSCRIPTEN__ && !defined __CYGWIN__
...

That should look up the address of SetThreadDescription instead of trying to use it directly.