如何在MSVC中使用MingW编译的库? [英] How to use libraries compiled with MingW in MSVC?

查看:1437
本文介绍了如何在MSVC中使用MingW编译的库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经编译了几个库与MingW / MSYS ...生成的静态库总是.a文件。
当我尝试链接库与MSVC项目,Visual Studio抛出'未解决的外部符号'...这意味着.a静态库与MS C ++链接器不兼容。我假设它必须转换为MSVC兼容的.lib文件。

I have compiled several libraries with MingW/MSYS... the generated static libraries are always .a files. When I try to link the library with a MSVC project, Visual Studio throws 'unresolved external symbols' ... It means that the .a static library is incompatible with MS C++ Linker. I presume it has to be converted to a MSVC compatible .lib file.

.a和.lib只是.o或.obj文件的AR存档,有什么办法如何使用MingW编译libs在MSVC项目?或者,我必须编译/链接所有只是在一个编译器/链接器 - MSVC only / MingW only?
MingW编译器据说与MSVC兼容。

Either .a and .lib are just AR archives of .o or .obj files, so is there any way how to use MingW compiled libs in a MSVC project? Or do I have to compile/link everything just in one compiler/linker - MSVC only/MingW only? The MingW compiler is said to be compatible with MSVC.

我读了几个关于这个主题的线程,但他们大多是说将文件重命名为.lib

I read a few threads about this topic, but they mostly say that renaming the file to .lib should do the work, but it unfortunately doesn't work for me.

试图链接的库Im是用C编写的。

The libraries Im trying to link are written in C.

MSVC Linker抛出类似以下错误:

MSVC Linker throws errors like:

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


b $ b

...和另外4个相同的错误,指的是从我的应用程序调用的其他函数。

... and 4 more same errors referring to other functions called from my app.

感谢任何建议。

推荐答案

根据此错误,您输入注释:

Based on this error you put in a comment:


error LNK2019:unresolved external
symbolint __cdecl
openssl_call(struct ssl_State
*,int,int,int)(?openssl_call @@ YAHPAUssl_State @@ HHH @ Z)
在函数_main中引用MyAPP.obj
所有其他4个错误仅与
相同其他函数名称

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

在你的include文件中放置 externC。例如:

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

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

使用 externC将指示编译器函数使用C链接,而不是C ++,这将阻止它执行名称修改。因此,它将在库中查找函数openssl_call,而不是?openssl_call @@ YAHPAUssl_State @@ HHH @。

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

这篇关于如何在MSVC中使用MingW编译的库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆