简体   繁体   English

使用 MinGW 编译的库可以与 MSVC 一起使用吗?

[英]Do libraries compiled with MinGW work with MSVC?

Problem:问题:
I would use a MinGW library in Visual Studio project.我会在 Visual Studio 项目中使用 MinGW 库。

How my system is built:我的系统是如何构建的:

I downloaded ZBar library for my Windows 10 system ( zbar-0.23.91-win_x86_64-DShow.zip我为我的 Windows 10 系统下载了 ZBar 库(zbar-0.23.91-win_x86_64-DShow.zip
This is the link: https://linuxtv.org/downloads/zbar/binaries/ ).这是链接: https://linuxtv.org/downloads/zbar/binaries/ )。

I have these files in the folder of lib and bin:我在 lib 和 bin 的文件夹中有这些文件:

  • libzbar.a libzbar.a
  • libzbar.dll.a libzbar.dll.a
  • libzbar.la libzbar.la
  • libzbar-0.dll libzbar-0.dll

Error when build:构建时出错:
error LNK2019: unresolved external symbol __mingw_vsnprintf referenced in snprintf错误 LNK2019:在 snprintf 中引用的未解析的外部符号 __mingw_vsnprintf

My question我的问题
Do libraries compiled with MinGW work with MSVC?使用 MinGW 编译的库可以与 MSVC 一起使用吗?

This error message is so easy to search in Google.此错误消息很容易在 Google 中搜索。 Add -lmingwex to the linker flags, the required library is libmingwex.a from MinGW distribution.将 -lmingwex 添加到 linker 标志,所需的库是来自 MinGW 发行版的 libmingwex.a。

The problem is that the libraries have been compiled with mingw while I need to compile them in an mscv project.问题是这些库是用 mingw 编译的,而我需要在 mscv 项目中编译它们。

The solution was to rebuild the library with Visual Studio.解决方案是使用 Visual Studio 重建库。

It was possible to use everything without problems.可以毫无问题地使用一切。

You can use C-lion because It has direct support of MinGW.您可以使用 C-lion,因为它直接支持 MinGW。 A sample tutorial for how to select MinGW as a toolchain in C-lion is given in this link.此链接中提供了有关如何将 select MinGW 作为 C-lion 中的工具链的示例教程。

https://www.jetbrains.com/help/clion/how-to-create-toolchain-in-clion.html#custom-targets-toolchain https://www.jetbrains.com/help/clion/how-to-create-toolchain-in-clion.html#custom-targets-toolchain

在此处输入图像描述

Using this you will have direct access to all the libraries available for MinGW directly.使用它,您将可以直接访问所有可用于 MinGW 的库。

No it can't.不,它不能。 A library compiled with MinGW will only work with MinGW.使用 MinGW 编译的库仅适用于 MinGW。 You need to compile it from source code with MSVC.您需要使用 MSVC 从源代码编译它。
I haven't used windows much and hardly used visual studio.我没有使用过 windows 并且几乎没有使用过 Visual Studio。 But you can use MinGW on visual studio ide if you want.但是如果你愿意,你可以在 Visual Studio ide 上使用 MinGW。
Using MinGW with Visual Studio IDE 将 MinGW 与 Visual Studio IDE 一起使用

No, libraries compiled on MinGW can't be used with MSVC.不,在 MinGW 上编译的库不能与 MSVC 一起使用。 The main reasons are:主要原因是:

  • Lack of ABI compatibility.缺乏 ABI 兼容性。 That is to say that in binary, the way things can be laid out are different depending on the compiler.也就是说,在二进制中,事物的布局方式因编译器而异。
  • Difference in how the standard library is implemented.标准库实现方式的差异。 The standard library can be implemented in many ways.标准库可以通过多种方式实现。 The C++ Standard just says how functions should behave and does not force compiler developers to implement them in the same way. C++ 标准只是说明函数的行为方式,并不强制编译器开发人员以相同的方式实现它们。

In general, things compiled with one compiler aren't compatible with another compiler.一般来说,用一个编译器编译的东西与另一个编译器不兼容。

You can't complie the same source code to on two different compilers.您不能在两个不同的编译器上编译相同的源代码。 Library function definitions are different, so you may get errors during the compilation.库 function 定义不同,因此在编译过程中可能会出错。

Solution will be just check which pre-defined functions are not working in MVSC, then create user-defined function with MVSC library.解决方案是检查哪些预定义函数在 MVSC 中不起作用,然后使用 MVSC 库创建用户定义的 function。

For example例如

clrscr() defined in conio.h not work on clang compiler instead you can create a pre-defined function or use system() . conio.h中定义的clrscr()不适用于 clang 编译器,您可以创建预定义的 function 或使用system()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在 MSVC 中使用使用 MingW 编译的库? - How to use libraries compiled with MingW in MSVC? 在MinGW编译的项目中使用MSVC编译的Boost二进制文件 - Use of MSVC-compiled Boost binaries in a MinGW-compiled project 如何在Visual Studio中使用通过MingW编译的库? - How to use libraries compiled with MingW in Visual Studio? 在MinGW构建的项目中链接MSVC编译的DLL - Link a MSVC compiled DLL in a MinGW-built project 如何在 VisualStudio 中将 MinGw 编译的库与 MSVC 项目链接? - How to link MinGw-compiled library with MSVC project in VisualStudio? 在由g ++(mingw)编译的应用程序中使用使用visual studio编译的库 - Use libraries compiled with visual studio in an application compiled by g++ (mingw) 如何在使用MinGW 32编译的Qt框架中使用用MSVC 14.0编译的库? - How can I use a library compiled with MSVC 14.0 in the Qt framework compiled with MinGW 32? 导入库是如何工作的,为什么 MinGW 不需要它们? - How do import libraries work and why doesn't MinGW need them? Qt5:此代码可以与msvc2012一起编译,但是却给出了用MinGW编译的错误…为什么? - Qt5: This code compiles ok with msvc2012, yet gives error compiled with MinGW… Why? 如何链接使用 MSVC 和 AddressSanitizer 编译的程序 - How do I link program compiled with MSVC and AddressSanitizer
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM