How to use libraries compiled with MingW in MSVC?

来源:互联网 发布:蛀牙漱口水 知乎 编辑:程序博客网 时间:2024/06/06 11:41

http://stackoverflow.com/questions/2529770/how-to-use-libraries-compiled-with-mingw-in-msvc

http://blogs.msdn.com/b/vijay/archive/2009/10/02/what-is-name-decoration-or-name-mangling.aspx

Based on this error you put in a comment:

error LNK2019: unresolved external symbol "int __cdecl openssl_call(struct ssl_State *,int,int,int)" (?openssl_call@@YAHPAUssl_State@@HHH@Z) referenced in function _main MyAPP.obj all other 4 errors are same only with other functions names

Try putting extern "C" around your include files for openssl. For example:

extern "C" {include "openssl.h"}

using extern "C" will instruct the compiler that the functions are using C linkage, not C++, which will stop it from performing name mangling on the functions. So it will look for the function openssl_call in the library rather than ?openssl_call@@YAHPAUssl_State@@HHH@.

http://lists-archives.com/mingw-users/05372-linking-with-windows-vssapi-dll.html

Many years ago, I had to interface to a third-party dll forwhich I simply couldn't manage to build an import librarythat worked, despite much effort. So I fell back on what Iguess is the most elementary, brute-force technique, andwrote a '.def' file by hand--and that worked.NAME 'WHATEVER'EXETYPE WINDOWSIMPORTS  _WhateverNameYouWant =GOOFY_DLL.GoofyInternalName  [Snip hundreds of other functions...but you want only one]That was the magic glue that let me call an msvc-builtdll from an application built with a different proprietarycompiler. Later, I rebuilt my application with gcc, creatinga gcc import library this way:libGOOFY_DLL.a: $(some_directory)/GOOFY_DLL.dll GOOFY_DLL.def        $(DLLTOOL) \          --dllname GOOFY_DLL.dll \          --input-def $(src_dir)/GOOFY_DLL.def \          --output-lib libGOOFY_DLL.a

原创粉丝点击