Compiling C++ for OSX from Windows - c++

I have a small console based, standards compliant, C++ program that I developed in Visual Studio on Windows. Since it is in standard C++, is all I need to do is compile it for OSX? or am I being overly optimistic?
I am looking for the easiest and most straightforward way to do this. Is it possible to do from Visual Studio 2012 Professional? If necessary I have access to a Mac. However, since my dev platform is Windows, it would be nice if I could do it from here.
I'm not experienced with mac development at all. When you compile an application for OSX, what do you get instead of a .exe?

If you don't mind installing MinGW or Cygwin to your Windows machine, you can build a Windows to OS X cross-toolchain as per the instructions here: https://github.com/Tatsh/xchain

I would get an OSX system (a VM is fine), install XCode and then compile your code using that. Should be trivial if your C++ code is written in a cross platform way.

Related

Is it possible to compile from Windows to Linux with gcc/g++?

Apologies for the beginner question.
In short I'm trying to compile a very simple C++ program for Linux from Windows 10. A few answers say "install cygwin" but I'm not sure it's the optimal solution. Would it be simpler to just install Linux and build for Linux from Linux and for Windows from Windows, or do cross-compilers already exist that could take care of the work for me?
Thank you
Edit: maybe my question wasn't clear. Essentially, I'm using VSCode on Windows. I have C++ code that I'd like to compile for Linux from Windows. I installed MinGW and it lets me compile Windows executables without issue. However I have no idea on how to compile executables for Linux.
You have several choices:
WSL.
WSL(Windows Subsystem for Linux) its linux termanal in windows, so you can compile linux code in windows. This solution is the simpliest and I would recommend to use it.
Visual studio.
Visual studio has a package that allows you to compile programs for Linux. More details here
The Linux and Windows libraries have some implementation differences. And also have different executables. Windows project may not work on Linux. But you can use the Visual Studio IDE with the Linux Developer Extension. Or can use WSL (Linux terminal for Windows) with Visual Studio Code (just install correct extension).
Compiling a very simple C++ program for Linux from Windows 10 can be done on a vanilla Windows 10 system by installing an Arm-provided, mingw32, toolchain:
Aarch32/Arm 32 bit:
gcc-arm-10.3-2021.07-mingw-w64-i686-arm-none-linux-gnueabihf
Aarch64/Arm 64 bit:
gcc-arm-10.3-2021.07-mingw-w64-i686-aarch64-none-linux-gnu
I'm sorry, I didn't quite understand the question. But when I start linux and try to make a C++ program. I started by trying to install the compiler through the terminal, then made a simple C++ program, and it worked. To begin with I visited this site :
https://linuxconfig.org/how-to-install-g-the-c-compiler-on-ubuntu-18-04-bionic-beaver-linux
Hopefully can help

How to compile C++ for Mac OS X using Visual Studio on Windows and CMake

I read that Visual Studio now supports cross-platform development. I'm using CMake to compile for Windows and Ubuntu (using WSL) so far. However there doesn't seem to be any information on how to actually accomplish the cross-compilation using Visual Studio to target Mac OS X. Is it doable with the CMakeSettings.json? According to this article, you can choose Linux-Debug and Linux-Release as configurationType but in Visual Studio 2017 Enterprise the Linux options aren't even available for me, neither is Mac OS X.
I might just setup a virtual machine as suggested in this post which seems to be the most convenient solution to get the job done.
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.
Alternatively, if you can get your hands on an (old) Macbook or so you can use that and enable network sharing to your main machine (e.g. a Windows PC). This way you can grab freshly compiled binaries directly from your Macbook using Windows and you're set with compiling your macOS builds.

Write C++ on Windows but use Linux System calls through a Linux emulator

I would like to develop C++ on Windows because I prefer the Visual Studio IDE (eclipse on Linux isn't very nice). However, eventually I will migrate to Linux and some of the code I will be writing will use low-level OS system calls.
Is there any way I can install a Linux emulator (not sure what you call it) on Windows, write Linux system calls in Visual Studio 2012 and have these system calls target the emulator, rather than the Windows OS?
I have tagged VS2010 but I can use VS2012 also.
Windows OS is Win 7.
You've already tagged your question with Cygwin. That seems like the best solution for what you want. Cygwin is basically a collection of programs which emulate a GNU/LInux environment through the use of a
DLL (cygwin1.dll) which acts as a Linux API layer providing
substantial Linux API functionality.
Here's the link to the documentation for its API
Edit: Most of the Cygwin source code that I've looked at is written in C++ and makes system calls using MS Windows API to do provide the *nix emulation. The source is well written and very readable (even to to a non-C++ programmer such as myself). I think using Cygwin would be a good transition from programming on Windows to a GNU/Linux environment.

C++ MinGW how to compile for Linx from Windows

I currently have MinGW for Windows and would like to develop for Linux(I have read that I need Headers), where would I get Linux headers and set up to compile both Windows and Linux programs with MinGW code::blocks.
Note: I have researched but could not find anything from Windows to Linux only Linux to Windows.
I do not exactly see what you mean by "develop", but if you want to work in an environment that produces binaries for some Linux system, you can not really "develop" because you cannot really run / debug them on Windows (when using cross-compilation).
On the other hand, if you want to develop code that compiles on Linux, you are already there. Since you are developing using MinGW, you are pretty much guaranteed that your code will compile under Linux with corresponding version of GCC. To produce a binary for the Linux distribution of choice, you can use VM, speed should not matter since you are not probably going to do it often.

How to compile C++ application for Unix/Linux in Windows

I have an application written in C++ using wxWidgets. How can I compile it for Linux and Unix os like Debian, FreeBSD, CentOS, in Windows?
Thanks!
Not entirely sure if I understood the question, but I think you are asking if you can compile an application for linux using a compiler in the windows environment.
My short answer: No, but.
The but: You may be able to use Cygwin in windows, however I think there is an easier way. If you are uncomfortable with setting up your computer to have multiple partitions and installing linux on at least one of these partitions, you can use VirtualBox, VMWare, or similar virtualization software to "install" linux on your windows machine. From there you can set up build environments and such. As for how, I would leave your windows build as is, but then in create a Makefile for Linux (or use CMake to replace both your windows-specific builder (the vsproj if using visual studio, etc) and linux-specific builder (make)) so that your source will compile both on windows and linux without having to modify the actual code or project.
i would recommend to use CMake as build system