The problem with linking different object files together, as a rule, comes down to calling subroutines. In principle, when you make a call to a routine located in another object file, your compiler will need to know what this other object file will call its internal procedure, how to transfer all its parameters, and what (if any) setup and cleaning code will require routine. All of these materials are usually grouped under the heading of a calling agreement .
Each compiler has its own calling conventions, which he likes to use for routines. Notice, I said "compiler", not a language. The C calling convention on Linux is different from the C calling convention on Windows.
Therefore, when you mix languages, you need to somehow tell the compiler that the calling convention of the other language is used for the calling or called routine. The C convention is popular for use as a kind of "lingua franca", since almost every platform has a C compiler. However, on some platforms (for example: Windows) there are several popular calling conventions.
So now we ask the question that you asked in the comments:
Is there a common way to "tell the compiler to use a convention about calling another language"?
And the answer: "No, not really." Some languages have identified ways to use special conventions for other languages. For example, C ++ allows you to put extern "C" in declarations to tell the compiler that the declarations in use are using the C calling convention. Ada does the same with pragma Convention (X,...) , where X is the name of the convention. C , Fortran and Cobol defined by the language, but anything that is supported (for example: Windows' Stdcall ) is determined by the implementation.
However, if you have a couple of languages whose compilers never thought of each other, then you have no choice but to say that you need to use the third convention, which they both know (usually C). For example, to interact with standard C ++ and Ada, you must have server code exporting your routines using the C convention and tell the client code that the routines it invokes use the C convention.