我可以用gcc编译一个函数,然后用clang吗? [英] Can I compile a function with gcc and then use it with clang?

查看:307
本文介绍了我可以用gcc编译一个函数,然后用clang吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图使用clang / llvm使用SSE4.2内在函数,但它没有编译,因为我得到不能从LLVM选择内在的错误。另一方面,相同的代码在gcc中无瑕疵地编译。所以我想,也许我可以编译该函数与gcc,以便有一个对象或库文件,然后调用该库函数在我的代码,这是由clang / llvm编译。

I am trying to use SSE4.2 intrinsics with clang/llvm but its not compiling, as I get cannot select intrinsic error from LLVM. On the other hand, the same code compiles flawlessly in gcc. So I thought, maybe I can compile that function with gcc, so as to have an object or library file, and then call that library function in my code, which is compiled by clang/llvm. Would that work?

推荐答案

可以使用GCC在Linux中编译一个目标文件,并将其转换为在Visual Studio中工作。我最近在Windows上在Virtual Box中运行Linux converting-c-object-file-from-linux-o-to-windows-obj ,所以在Linux或Windows上也应该可以使用Clang。

It's possible to compile an object file with GCC in Linux and convert it to work in Visual Studio. I did this recently running Linux in Virtual Box on Windows converting-c-object-file-from-linux-o-to-windows-obj so this should be possible with Clang on Linux or Windows as well.

因此,不仅可以通过交叉编译器完成跨平台

您需要获得调用约定和目标文件格式正确(以及对于C ++的名称调整)。使用GCC编译时,可以告诉它使用 mabi 的调用约定/ API。然后,如果从Linux到Windows,你需要一个目标文件转换器从例如。 Linux上的ELF到Windows上的COFF。当然,有些情况下这可能不工作(例如,如果模块依赖于只在一个平台的系统调用)。有关详情,请参阅上面的链接。

You need to get the calling conventions and the object file format correct (and for C++ the name mangling as well) . With GCC when you compile you can tell it which calling convention/API to use with mabi. Then, if going from Linux to Windows, you need an object file converter to convert from e.g. ELF on Linux to COFF on Windows. Of course, there are cases this probably won't work (e.g. if the module relies on a system call that is only in one platform). See the link above for more details.

这篇关于我可以用gcc编译一个函数,然后用clang吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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