Visual Studio 2015 c++/CLI boost::thread [duplicate]

眉间皱痕 提交于 2020-01-23 12:28:24

问题


This issue has been around for all Visual Studio versions, but in VS 2015 the "old tricks" don't seem to work anymore.

This is what I have tried:

  • create a Windows Forms application in VS 2013 and 2015 (the macro is missing since VS 2013, so see this post: Can't find Windows Forms Application for C++)

  • add boost headers path to Additional Include Directories

  • add #include "boost/thread.hpp" in the cpp

  • add the following preprocessor definitions (BOOST_USE_WINDOWS_H;BOOST_ALL_NO_LIB;BOOST_ALL_DYN_LINK)

  • add linker dependencies to boost thread and system libs

Building the small test application compiles and links with both VS 2013 and 2015. But when starting the application built in VS 2015, the app crashes:

Exception thrown at 0x0000000077C3EB18 (ntdll.dll) in TestCLRForms.exe: 0xC0000005: Access violation reading location 0xFFFFFFFFFFFFFFFF.

This is the call stack:

ntdll.dll!0000000077c3eb18()    Unknown
KernelBase.dll!000007fefdcd304a()   Unknown
ucrtbased.dll!000007fee02bdeb1()    Unknown
ucrtbased.dll!000007fee02bf9d7()    Unknown
ucrtbased.dll!000007fee02c0438()    Unknown
ucrtbased.dll!000007fee02bfb79()    Unknown
ucrtbased.dll!000007fee02e981d()    Unknown
ucrtbased.dll!000007fee02e9545()    Unknown
ucrtbased.dll!000007fee02e962c()    Unknown
ucrtbased.dll!000007fee02e9d6f()    Unknown
TestCLRForms.exe!_onexit(int(*)() function=0x000000013f627b50) Line 268 C++
TestCLRForms.exe!atexit(void(*)() function=0x000000013f627b50) Line 276 C++
TestCLRForms.exe!__scrt_initialize_thread_safe_statics() Line 109   C++
[Managed to Native Transition]  
TestCLRForms.exe!_initterm_e(int (__cdecl*)()* pfbegin=0x00000000001ad680, int (__cdecl*)()* pfend=0x00000000001ad688) Line 69  C++
TestCLRForms.exe!<CrtImplementationDetails>::LanguageSupport::InitializeNative() Line 355   C++
TestCLRForms.exe!<CrtImplementationDetails>::LanguageSupport::_Initialize() Line 598    C++
TestCLRForms.exe!<CrtImplementationDetails>::LanguageSupport::Initialize() Line 805 C++
TestCLRForms.exe!.cctor() Line 856  C++
[Native to Managed Transition]  
[Managed to Native Transition]  
[Native to Managed Transition]  
mscoreei.dll!000007fef8107fd5() Unknown
mscoree.dll!000007fef81a5b21()  Unknown
kernel32.dll!0000000077b159cd() Unknown
ntdll.dll!0000000077c4a2e1()    Unknown

Tested only for x64.

Does anyone have an idea? Thanks


回答1:


I found a workaround that (at least partially) solves the above problem. I post it here, someone else might find it useful.

If the SubSystem option in Linker/System is set to Console and the Entry Point in Linker/Advanced is left blank (important!), then the crash doesn't occur and the app works. The disadvantage of this workaround is that a console window is opened alongside with the GUI application.

I personally can live with this, because my application is just a test program, but for others it might not be acceptable.

The original question remains open if someone can find a better solution.




回答2:


You can change Properties->Linker->Advanced->Entry Point to ?mainCRTStartupStrArray@@$$FYMHP$01AP$AAVString@System@@@Z (32 bit, see https://bytes.com/topic/net/answers/642179-c-cli-winforms-app-native-static-library-singletons-cra) or

?mainCRTStartupStrArray@@$$FYMHP$01EAPE$AAVString@System@@@Z (64 bit, thanks to @Hans Passant, who answered my question Entry point for C++/CLI x64 WindowsForms App (VS 2015))

Then the application should start normally.



来源:https://stackoverflow.com/questions/40081419/visual-studio-2015-c-cli-boostthread

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!