英文:
Are c++ module files platform independent / cross platform?
问题
我有一个大的.cpp文件,编译需要很多分钟,我想与朋友分享,他们有一台arm机器,而我有一台x86机器。我能否在我的机器上将其制作成一个C++模块,然后通过电子邮件发送给我的朋友,以便他们可以在无需编译大的.cpp文件的情况下使用该模块?如果有关系的话,我们都在运行相同类型的操作系统,并且使用来自同一供应商的编译器。
英文:
I have a large .cpp file that takes many minutes to compile, I want to share it with a friend, they have an arm machine, and I have an x86 machine. Can I make it a c++ module on my machine and email it to my friend so they can use the module without having to compile the large .cpp file? We are both running the same type of operating system and are using compilers from the same vendor if that matters.
答案1
得分: 2
标准规范中没有指定这些内容,因此对不同的编译器和平台来说可能会不同。但通常,模块编译的输出产品包括目标文件(库文件,因此肯定是特定于CPU的)和模块文件。后者至少是编译器特定的(甚至可能对编译器的版本敏感),而且很可能是特定于CPU或操作系统的(特别是如果您有任何与CPU特定相关的#ifdef
条件)。将源文件交给他们,让他们自己构建模块一次,会更具可移植性。
英文:
None of this is specified by the standard, so it will be different for different compilers and platforms. But usually, the output products of a module compilation are object files (libraries, so definitely CPU-specific) and module files. The latter are at the very least compiler specific (and may even be sensitive to compiler versions) and can very well be CPU or OS specific (especially if you have any #ifdef
s that are CPU-specific).
It would be much more portable to just hand them your source files and let them build the module one time themselves.
答案2
得分: -2
使用模块编写的代码应该在支持C++20标准的不同平台和编译器之间具有可移植性。然而,关键在于你和你的朋友使用的特定编译器是否支持C++20模块。
英文:
Code written using modules should be portable across different platforms and compilers that support the C++20 standard. However, the key here is the support for C++20 modules by the specific compiler you and your friend are using.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论