llvm-gcc 和 clang 二进制文件与 gcc 兼容吗?- 特别是 Windows 上的 mingw gcc [英] Are llvm-gcc and clang binary compatible with gcc? - particularly mingw gcc on Windows

查看:30
本文介绍了llvm-gcc 和 clang 二进制文件与 gcc 兼容吗?- 特别是 Windows 上的 mingw gcc的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我用 llvm-gcc 构建一个静态库,然后将它与使用 mingw gcc 编译的程序链接,结果会起作用吗?

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

llvm-gcc、clang 和普通 gcc 的其他组合也是如此.我对这在 Linux(当然,使用普通的非 mingw gcc)和其他平台上的效果很感兴趣,但重点是 Windows.

The same for other combinations of llvm-gcc, clang and normal gcc. I'm interested in how this works out on Linux (using normal non-mingw gcc, of course) and other platforms as well, but the emphasis is on Windows.

我也对所有语言都感兴趣,但特别强调 C 和 C++ - 显然 clang 不支持 Fortran 等,但我相信 llvm-gcc 支持.

I'm also interested in all languages, but with a strong emphasis on C and C++ - obviously clang doesn't support Fortran etc, but I believe llvm-gcc does.

我假设它们都使用 ELF 文件格式,但是调用约定、虚拟表布局等呢?

I assume they all use the ELF file format, but what about call conventions, virtual table layouts etc?

推荐答案

是的,对于 C 代码,Clang 和 GCC 是兼容的(事实上,它们都使用 GNU 工具链进行链接.)你只需要确保你告诉clang 来创建编译对象而不是中间位码对象.C ABI 定义明确,所以唯一的问题是存储格式.

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++ 一点也不能在编译器之间移植;不同的编译器使用不同的虚拟表调用、构造函数、销毁、名称修改、模板实现等.通常,您应该假设来自一个 C++ 编译器的对象不能与另一个编译器一起使用.

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.

但是,在撰写本文时,Clang++ 也能够使用 GCC/C++ 编译库;我最近设置了一个钻机,使用 G++ 的标准运行时库用 clang 编译 C++ 程序,它编译 + 链接就好了.

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.

这篇关于llvm-gcc 和 clang 二进制文件与 gcc 兼容吗?- 特别是 Windows 上的 mingw gcc的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆