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

查看:1002
本文介绍了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 ++ - 显然ang不支持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创建编译对象,而不是中间bitcode对象。 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天全站免登陆