Are llvm-gcc and clang binary compatible with gcc? - particularly mingw gcc on Windows

后端 未结 5 772
旧时难觅i
旧时难觅i 2020-12-14 07:30

If I build a static library with llvm-gcc, then link it with a program compiled using mingw gcc, will the result work?

The same for other combinations of llvm-gcc, c

5条回答
  •  庸人自扰
    2020-12-14 07:39

    Yes, for C code Clang and GCC are compatible (they both use the GNU Toolchain for linking, in fact.) You just have to make sure that you tell clang to create compiled objects and not intermediate bitcode objects. C ABI is well-defined, so the only issue is storage format.

    C++ is not portable between compilers in the slightest; different compilers use different virtual table calls, constructors, destruction, name mangling, template implementations, etc. As a rule you should assume objects from one C++ compiler will not work with another.

    However yes, at the time of writing Clang++ is able to use GCC/C++ compiled libraries as well; I recently set up a rig to compile C++ programs with clang using G++'s standard runtime library and it compiles+links just fine.

提交回复
热议问题