問(wèn)題提出:
別人提供MSVC下編譯好的dll動(dòng)態(tài)庫(kù),我需要調(diào)用并在MinGW下編譯。
1 直接鏈接dll,當(dāng)然行不通。
2 鏈接MSVC下編譯dll時(shí)產(chǎn)生的lib函數(shù)符號(hào)表,仍有問(wèn)題,函數(shù)定義找不到。
3 通過(guò)reimp工具將MSVC下的lib轉(zhuǎn)為.a,失敗。
4 通過(guò)pexports工具,根據(jù)dll生成def文件,再通過(guò)dlltool生產(chǎn).a文件,仍然報(bào)告找不到函數(shù)定義。
pexports testdll.dll>testdll.def,//是否需要sed工具加入,還有待考證
dlltool -d testdll.def -D testdll.dll -l libtestdll.a //是否需要-U 選項(xiàng),加了仍然失敗
以上都是通過(guò)g++產(chǎn)生的問(wèn)題。
如果是gcc來(lái)編譯C項(xiàng)目,那么可以直接鏈接MSVC的lib。
至此,還沒(méi)有找到g++編譯MSVC下的dll方法。有網(wǎng)友如此說(shuō)明:
They have exported C++ classes from their dll, rather than C-functions. The difference is, c++ functions are always exported with names in a mangled form that is specific to a particular version of the compiler.
Their dll is usable by msvc only in that form, and will probably not even work between different versions of msvc, as Microsoft have changed their mangling scheme before.
If you have any leverage, you need to get them to change their evil ways. Otherwise you will need to use MSVC to write a shim dll, that will import all the classes, and re-export them via c functions that return interfaces.
其他參考資料有:
http://www.mingw.org/wiki/MSVC_and_MinGW_DLLs 可繼續(xù)加入sed工具嘗試
http://stackoverflow.com/questions/2472924/linking-to-msvc-dll-from-mingw 可惜找不到發(fā)帖人的聯(lián)系方式
http://www.360doc.com/content/10/0907/16/169163_51891922.shtml 僅是簡(jiǎn)單的命令操作
http://wiki.videolan.org/GenerateLibFromDll 還未嘗試