I'm using VC++ 2015 to compile the following program.
#include <oleacc.h>
#include <unordered_map>
#pragma comment(lib,"User32.lib")
#pragma comment(lib,"Oleacc.lib")
thread_local std::unordered_map<int, int> something ;
int main( int argc, char* argv[] ){
MessageBox(0, "Program started", "Test program", MB_SETFOREGROUND) ;
IAccessible* test ;
AccessibleObjectFromWindow(GetForegroundWindow(), OBJID_WINDOW, IID_IAccessible, (void**)&test) ;
}
Command line:
cl test.cpp /EHsc /link /MACHINE:x86 /entry:mainCRTStartup /subsystem:windows,5.1
The program shows a message box and exits. It works fine on all Windows versions except Windows XP, in which nothing happens when the program icon is double-clicked.
There's no error message or any indication that the program failed. It just does nothing. It shows up in the task manager for a fraction of a second and then it disappears.
The following two elements must be present for the program to fail in Win XP.
- A
thread_local
unordered_map
in the global scope. - A call to
AccessibleObjectFromWindow
If I make any of the following changes, the program does work in XP:
- Changing
unordered_map
tostd::map
- Removing the
thread_local
keyword - Moving the
thread_local
variable insidemain
- Removing the call to
AccessibleObjectFromWindow
Is there any command line parameter I can pass to the compiler/linker so that the program works in WinXP?
UPDATE:
If I add /MD
to the command line (i.e. use the runtime installed in the OS), WinXP can run the program successfully.
This shows that the problem is some sort of incompatibility between Windows XP and the MSVC runtime library embedded into the executable by VS2015 (I also tried with VS2019, but made no difference).
I tried building a project through the GUI and selecting Windows XP (v140_xp) as the platform toolset, but the problem still occurs.
I guess my only option is to change unordered_map
to map
. Or to get rid of thread_local
somehow.