How to compile C / C ++ for Linux / Mac OS on a Windows?

4

The title says it all. I have code that can be compiled on the two (three?) Platforms and I wish to do it straight from Windows just using GCC (MinGW, in that case). Is this possible in relation to cross-compiling ? How would you do it in my case?

    
asked by anonymous 01.02.2015 / 18:53

1 answer

0

I think the most important thing is to do your project in a way that can be easily compiled on several platforms. I use the cmake ( cmake cross compiling a>). With cmake, I can compile for Visual Studio, GCC, MingW (cross-compiler installed on Linux), Clang (Mac and Linux) without any trauma, it's worth it.

The second step is to port your code to properly suit all platforms, let's assume you use sockets, the response of a connect timeout given by VC ++ is error 10060 with a predefined message , MingW can no longer retrieve the error message. Your application should anticipate these nuances of the platforms.

And you should download the Linux toolchain on Windows. I think downloading msys2 and installing cmake with a cross compiler from Linux would get papaya with sugar to compile your project. Although I do the opposite, I develop on the Linux machine and compile for Windows target, and the final distribution on a VM with VC ++.

Finally, if you do not have a toolchain in hand, you can create your own. Basically, you have to compile the binutils in Windows for the Linux target, and then compile gcc with the binutils you just compiled. I'll leave the reference how to create a crosscompiler for arduino, I use this method because I have always in hand the younger gcc, in the case of Arduino.

    
16.02.2017 / 21:21