問題提出:
別人提供MSVC下編譯好的dll動態庫,我需要調用并在MinGW下編譯。
1 直接鏈接dll,當然行不通。
2 鏈接MSVC下編譯dll時產生的lib函數符號表,仍有問題,函數定義找不到。
3 通過reimp工具將MSVC下的lib轉為.a,失敗。
4 通過pexports工具,根據dll生成def文件,再通過dlltool生產.a文件,仍然報告找不到函數定義。
pexports testdll.dll>testdll.def,//是否需要sed工具加入,還有待考證
dlltool -d testdll.def -D testdll.dll -l libtestdll.a //是否需要-U 選項,加了仍然失敗
以上都是通過g++產生的問題。
如果是gcc來編譯C項目,那么可以直接鏈接MSVC的lib。
至此,還沒有找到g++編譯MSVC下的dll方法。有網友如此說明:
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 可繼續加入sed工具嘗試
http://stackoverflow.com/questions/2472924/linking-to-msvc-dll-from-mingw 可惜找不到發帖人的聯系方式
http://www.360doc.com/content/10/0907/16/169163_51891922.shtml 僅是簡單的命令操作
http://wiki.videolan.org/GenerateLibFromDll 還未嘗試