问题提出:
别人提供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 还未尝试