How to use libraries compiled with MingW in MSVC?

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@.


The libraries are compatible, but only if you supply a C interface. MSVC and g++ use different name-mangling schemes, so you cannot easily link C++ code created with one with code created by the other.


I encounted the same situations that use mingw-compiled dll in MSVC. I use following tools to make it work:
1) use gcc like that:

gcc -shared -o your_dll.dll your_dll_src.c -Wl,--output-def,your_dll.def

The bolds specify that gcc will generate a *def file that scripts your exported items.Then you need to use lib.exe, which distributed with MSVC, example like this:

lib /def:your_dll.def

Then, there will be a your_dll.lib file, comes from lib.exe.(Assume that you_dll.dll located in the same directory as your_dll.def).

currently, I can use the *.lib in my MSVC project and link the dll correctly, but I got the runtime error. Anyway, such works make your linkage workable.