lyron
lyron

Reputation: 246

Boost python module not working on windows xp

I am trying to create my own python module with visual studio 2015 using boost python. When i try to import the module on windows xp, i get this error:

ImportError: DLL load failed: Invalid access to memory location.

I tried everything i could find, to make my boost python build compatible with windows xp such as using this option:

b2 release define=BOOST_USE_WINAPI_VERSION=0x0501

as described here Boost Version 1.60.0. Or setting environment variables before callig b2.

set "INCLUDE=%ProgramFiles(x86)%\Microsoft SDKs\Windows\7.1A\Include;%INCLUDE%"
set "PATH=%ProgramFiles(x86)%\Microsoft SDKs\Windows\7.1A\Bin;%PATH%"
set "LIB=%ProgramFiles(x86)%\Microsoft SDKs\Windows\7.1A\Lib;%LIB%"
set "CL=/D_USING_V110_SDK71_;%CL%"
set "LINK=/SUBSYSTEM:CONSOLE,5.01 %LINK%"

as descirbed here: Windows XP Targeting with C++ in Visual Studio 2012

How can i get the dll to work under Windows XP?

Upvotes: 1

Views: 165

Answers (1)

lyron
lyron

Reputation: 246

After some more investigation i came to this conclusion:

Visual Studio 2015 compiler behaviour has changed for Windows XP. I found the explanation for the behaviour here:

"We have a shell extension dll that run into a problem after upgrading to Visual Studio 2015 because the new Magic Static uses implicit TLS under the hood."

This means, VS2015 compiler will use TLS, but this storage will not be correctly initialized on Windows XP. Boost.Python will therefore crash because of uninitialized static variable.

There is a workaround:

"A workaround is to use compiler switch /Zc:threadSafeInit- as long as you do not otherwise rely on Magic Statics functionality."

Hope this helps others who have to support Windows XP

Upvotes: 1

Related Questions