Search code examples
c++linkermingwzbar

Do libraries compiled with MinGW work with MSVC?


Problem:
I would use a MinGW library in Visual Studio project.

How my system is built:

I downloaded ZBar library for my Windows 10 system ( zbar-0.23.91-win_x86_64-DShow.zip
This is the link: https://linuxtv.org/downloads/zbar/binaries/).

I have these files in the folder of lib and bin:

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

Error when build:
error LNK2019: unresolved external symbol __mingw_vsnprintf referenced in snprintf

My question
Do libraries compiled with MinGW work with MSVC?


Solution

  • No, libraries compiled on MinGW can't be used with MSVC. The main reasons are:

    • Lack of ABI compatibility. 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.

    In general, things compiled with one compiler aren't compatible with another compiler.