I would like to ask in more detail about a answer I recently got here (3rd one): Compiled languages basics
If I write in C and MinGW and I link to C++ library compiled by VC - will it work? How do I know in advance?
In other words, if I'm able to create without warnings an .exe which links to that C++ .dll, and I'm able to run (just run, no further testing) that .exe, does it mean it worked? Wont it core-dump at some point?
To be totally sure, do I need to re-compile the library sources by myself and the link with it?
I understand that there might be a problem sometimes with linking C++ and C code but how to know when it works and worked?
PS: Yes, I saw Use libraries compiled... I just thought my question is slightly different.
Yes, you can convert MSVC compiled libraries for MinGW without recompiling.
You need only couple of tools and the dll. Check out here.
Regarding mixing C and C++ - if you are not worried about the size of your binary, just use c++ compiler for your c projects. This way you will be not worried about the possible issues with the libs you are linking to.
It depends on the compilers (and I don't know MinGW) and on the specific C++ library.
Reasons why it might not link, or might crash if it does link:
The C++ library is exporting C++ classes and methods, using "mangled" names, but MinGW's C++ name mangling may (I don't know) be different than VC's (and non-existent when you're coding in C instead of C++)
VC code doesn't use the same C run-time library as MinGW, which will bite you if the API is such that memory is allocated on the heap by VC code and is then supposed to be freed by the MinGW code.
VC's code isn't binary-comptible with MinGW's code (doesn't use the same parameter-passing conventions, doesn't implement exceptions in the same way)
On the other hand, some reasons why it might work:
The C++ library is written with C-style interface, by developers who intended it to be called from a different compiler
Same as 1.
The makers of the MinGW compiler made it binary-compatible with VC
I don't know. If you post the names of the functions exported from the DLL, and/or the header file which declares its public/exported API, that would give me (or someone else) a very strong hint about whether it's exporting (possibly-incompatible) C++-style methods or exporting (more-likely-to-be-comptible) C-style functions.
Otherwise you have a two-stage question:
What does it take (e.g. C instead of C++, e.g. not assuming they use the same heap, e.g. specifiying the parameter-passing convention) for MinGW code to invoke VC code?
Has your VC library be written with that in mind?
Someone who has used both compilers could probably answer the first question (I haven't used MinGW). I don't know who could answer the second; who wrote that VC library?