问题描述
我想更详细地询问一个答案,我最近来到这里(第一个):
如果我写在C和MinGW和我链接到由VC编译的C ++库 - 将它的工作?我怎么事先知道吗?
在换句话说,如果我能够在没有警告,创建一个链接到C ++的.dll的.exe,我能够运行(只运行,没有进一步的测试),该.exe文件,是否意味着它工作?在某些时候它不会核心转储?
要完全肯定的是,我是否需要重新编译我自己的库源和链接呢?
据我了解,有可能是一个问题,有时连接C ++和C code,但如何知道什么时候它的工作原理和工作?
PS:是的,我看到了
Use库编译...
我只是觉得我的问题略有不同。
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?
这篇关于通过各种编译器编译链接库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!