boost靜態連接庫和c++/clr不兼容問題:未能加載文件或程序集,不是有效的Win32應用程序。

轉自:http://blog.csdn.net/h807892124/article/details/51326552c++

項目上遇到的問題:c++編寫的類使用託管c++包裝成dll提供給c#項目使用。c++須要使用boost,clr,項目目標平臺都是win32/x86。開發環境win10 x64系統,vs2013,.Net Framework 4.0,boost 1.55。c#

【問題表現】c#程序在win10 x86/x64正常運行,但在win7 x86/x64運行時發生異常:
Additional information: Could not load file or assembly 「LicenseClientDLL_D.dll」 or one of its dependencies. is not a valid Win32 application. (Exception from HRESULT:0x800700C1)
這裏寫圖片描述windows

【緣由】boost庫默認使用靜態連接方式,但boost靜態連接庫和C++/clr不兼容,因此要換成動態連接。
stackoverflow上相關資料:
[引用]Too many comments in the net saying boost static libs and CLR are not compatible.
[引用]It was the boost libraries having some issue when compiled without /clr but linked to a program that uses /clrapp

【解決方案】c++使用boost動態連接庫。
1.在須要使用boost庫的項目的「預處理器定義」增長 BOOST_THREAD_DYN_LINK (要求動態連接boost庫)
2.手動拷貝須要引用的boost庫文件到項目路徑 libboost、boost開頭的lib文件(BOOST_LIB_DIAGNOSTIC 該宏能夠查看須要的boost庫)
3.從新編譯.net

相關文章
相關標籤/搜索