0

By my understanding compilers like mingw, clang, mvs c++ simply take source code written in C++ and try to generate senseful object code and maybe create an executeable that may or may not follow the developer's intentions.

However I noticed that for example OpenCV may cause linkage errors, if OpenCV and the code using it were compiled by different compilers. Why is that? What does using different compilers accomplish?

Imago
  • 521
  • 6
  • 29
  • 1
    A lot of things in the C++ standard are either implementation-defined or unspecified, which means each compiler is free to do what it wants - and different compilers do those things differently. Examples include size of basic types (`int`, `float`, etc), layout of data structures, different calling conventions (related to how arguments are supplied to functions). The standard also REQUIRES function names to be named/mangled differently by different compilers. All of these are source of incompatibilities, but also allow different compilers to have features that suits different developers – Peter Jun 01 '19 at 06:56

2 Answers2

4

Why is that? What does using different compilers accomplish?

Well, using different compilers might accomplish using different (and incompatible) ABI's.

In general the libraries you use should be compiled that these are compatible with your target compiler (linker) ABI.

πάντα ῥεῖ
  • 1
  • 13
  • 116
  • 190
1

OpenCV may cause linkage errors, if OpenCV and the code using it were compiled by different compilers. Why is that?

Different C++ compilers may have different name mangling. As a result, the linking process is not able to link names generated by different compilers.

What does using different compilers accomplish?

Using different compilers allows a developer to find out issues with portability of the code.

bhardwajs
  • 424
  • 4
  • 6