您的位置:首页 > 其它

How to use libraries compiled with MingW in MSVC?

2013-01-17 21:37 357 查看
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 for
which I simply couldn't manage to build an import library
that worked, despite much effort. So I fell back on what I
guess is the most elementary, brute-force technique, and
wrote a '.def' file by hand--and that worked.

NAME 'WHATEVER'
EXETYPE WINDOWS
IMPORTS
_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-built
dll from an application built with a different proprietary
compiler. Later, I rebuilt my application with gcc, creating
a 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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: