Why?
Depending on your source the Intel compiler is likely or most definitely the compiler generating the fastest executables for the x86 architecture (5 to 100 % execution time improvement).
Intel offers its compilers for Linux under a non-commercial license for free (I think I read it is free somewhere on their page: Intel – Non-Commercial Software Development).
There is also a free non-commercial license for students, but this license is not applicable although tools are offered for all three major operating systems (link dropped due to reputation restriction).
Goal
I (as a non-student) would like to be able to use the Intel compilers for possible execution speed improvements under the non-commercial license to compile object files that can be linked to create executables and dynamic link libraries for Windows (and possibly OS X)
More Details:
What I inferred from this document is that the Intel compilers create object files that are compatible to the dominant compilers of the platform.
Sub-questions:
- What are the object file formats of gcc, g++, cl, mingw32, icc, icpc, and icl on Windows and Linux (current versions)?
- Could parts of the mingw32 cross-compiler toolchain be used to accomplish the goal?
- Am I right that the metadata in the generated object files is the main issue?
ad 2:
mingw32-objcopy seems to be able to convert the Intel compiler output on Linux (presumably ELF) to Microsoft-compatible COFF (with the possible exception of relocateable object files). Could someone confirm that this actually works (for non-trivial applications), please?
6
It is possible to create Windows executables on a Linux build machine by using a cross-compiler. But, Intel does not provide such cross compilers.
To answer the sub-questions:
What are the object file formats of gcc, g++, cl, mingw32, icc, icpc, and icl on Windows and Linux (current versions)?
The format for the object files is effectively determined by the operating system (or rather, the compiler used to build it). For Windows, this is the Portable Executable (PE) format and for Linux the ELF format.
Could parts of the mingw32 cross-compiler toolchain be used to accomplish the goal?
No. The relevant part is the code generator, which is both the part responsible for generating the right object format and the part on the Intel compilers that gives their generated code the speed edge.
Am I right that the metadata in the generated object files is the main issue?
No. It is one issue, but there are more. A more fundamental problem is the potential difference in how parameters are passed to the kernel and/or standard library. IIRC, those conventions are different between Windows and Linux.
The answer is almost certainly yes. I know that cross-compiling Windows binaries (via mingw32) on a Linux box is easily possible using gcc – obviously you won’t be able to run the program on Linux (unless it works under Wine), but I know several programs that get Windows binaries this way.
However, I don’t know if the Intel compiler has the options for this, I should think it does.
The object format for Windows is PE, whereas for Linux its ELF.
2
With C code linking to nothing (directly) that uses Microsoft’s custom calling conventions, you might stand a chance using MinGW’s objcopy
. I have used it to convert an assembled object file, but then I didn’t have to worry about calling conventions.
I would just spend the time you would trying to do this instead getting GCC or clang to do exactly what you want. If such a speed up is really that important compile a Linux binary with the Intel compiler and try to see exactly what, if anything at all, it does speeding up your code. You can patch the assembly if all else fails.
I propose the following answer:
A definite maybe (leaning towards yes) with a but regarding the context.
Explanation:
Regarding the “leaning” part: It seems to not be a total waste of time to try this, but (the “put” part) taking into account this answer you likely won’t get the execution time improvements compared to an Intel-only toolchain. The relevant part being linker and runtime feedback to the compiler (whole program optimization, profile-guided optimization, link-time code generation).
Additional detail:
According to the MinGW FAQ there are possible problems with using libraries and DLLs:
“Although dlls are supposed to be fairly portable across different Windows compilers, accessing dlls through a library file (.lib or .a) is not. The library file formats are specific to particular compilers and cannot be used portably with different compilers unless the compiler provides support for it.”
To complete the answer:
sub-question 1:
What are the object file formats of gcc, g++, cl, mingw32, icc, icpc, and icl on Windows and Linux (current versions)?
The default object file format for any compiler on Windows is COFF (likely the PE variant).
The default object file format for any compiler on Linux is ELF
sub-question 2:
Could parts of the mingw32 cross-compiler toolchain be used to accomplish the goal?
Most likely yes (for the linking part), but most likely you will not get much execution time improvement.
sub-question 3:
Am I right that the metadata in the generated object files is the main issue?
Regarding linking: yes.