[英]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 的文件夹中有这些文件:
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:
主要原因是:
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.