How to Compile for OS X in Linux or Windows?
There appears to be some scripts that have been written to help get you set up cross compiling for the Mac; I can't say how good they are, or how applicable to your project. In the documentation, they refer to these instructions for cross-compiling for 10.4, and these ones for cross compiling for 10.5; those instructions may be more helpful than the script, depending on how well the script fits your needs.
If your program is free or open source software, then you may wish instead to create a MacPorts portfile (documentation here), and allow your users to build your program using MacPorts; that is generally the preferred way to install portable free or open source software on Mac OS X. MacPorts has been known to run on Linux in the past, so it may be possible to develop and test your Portfile on Linux (though it will obviously need to be tested on a Mac).
Compiling for Mac/Linux on Windows
Crosstool-NG seems like your best option for Linux apps; they show that as one of the standard configurations. I do not know about Mac OS X; this question suggests that it will probably be difficult.
Cross compile Go on OSX?
With Go 1.5 they seem to have improved the cross compilation process, meaning it is built in now. No ./make.bash
-ing or brew
-ing required. The process is described here but for the TLDR-ers (like me) out there: you just set the GOOS
and the GOARCH
environment variables and run the go build.
For the even lazier copy-pasters (like me) out there, do something like this if you're on a *nix system:
env GOOS=linux GOARCH=arm go build -v github.com/path/to/your/app
You even learned the env
trick, which let you set environment variables for that command only, completely free of charge.
How to compile C++ for Mac OS X using Visual Studio on Windows and CMake
Apparently you can't.
I ended up installing a virtual machine with Mac OS X
and successfully compiled my code inside it using shared folders to make my Windows
host source code available to the guest. This is certainly more reliable and sane to do than some hacky cross-compilation project. The latter still doesn't guarantee that the code will successfully run and not unexpectedly crash on the cross-compilation target operating system.
Way Cross Compile C/C++ code to run on Windows, Linux, and Mac OS?
You can cross compile with what is known as a cross-compiler. Mingw can be installed as such. I believe MacOS just uses g++ so you can probably make a cross compiler for it as well. Never done it myself. You can scour the web for directions. Here's the top link I got from google:
http://linux.bytesex.org/cross-compiler.html
Create a Static Library on Windows Which Is macOS and Linux Compatible
This is not possible in the simple way you want (one library file for each OS/compiler) due to the fact that static libraries are compiled binary code, which inevitably reference platform specifics and must (in general) be in a compiler specific format. Some level of compatibility exists between several compilers on the same OS, but never ever is that going to work across different OSes. Mac OS used to have the concept of fat binaries (in which both the 32-bit and 64-bit binary code resided next to each other), but since they moved to exclusively 64-bit, this isn't really relevant anymore (although they still exist and still can be used).
If you want to distribute in binary form, you will need to provide different binaries for each platform (OS/architecture/toolchain) combination you want to support.
Related Topics
How to Read Until Eof from Cin in C++
C++ Alignment When Printing Cout ≪≪
Why Isn't There a Std::Shared_Ptr≪T[]≫ Specialisation
Default Value of Function Parameter
Creating an Input Stream from Constant Memory
What Does It Mean When a Numeric Constant in C/C++ Is Prefixed With a 0
Erasing from a Std::Vector While Doing a For Each
How to Use Reference Parameters in C++
How to Convert Std::String to Lpcwstr in C++ (Unicode)
How Many and Which Are the Uses of "Const" in C++
How to Call a Function on All Variadic Template Args
Std::Thread Pass by Reference Calls Copy Constructor
C++11 Allows In-Class Initialization of Non-Static and Non-Const Members. What Changed
How Does This Template Magic Determine Array Parameter Size