Home > other >  Is it possible to write a C program on Windows for Linux
Is it possible to write a C program on Windows for Linux

Time:01-14

I'm creating a linux shell, and i've been developing it on a VirtualBox virtual machine of linux on my windows 10 pc. Recently I've upgraded to Windows 11 and for some reason that makes the vm run at unbearably slow speeds. Therefore i how to comply and not use the linux vm, so i need to develop the shell in windows and execute it using WSL2 or any other command line. Is it possibly to use the linux libraries (e.g : <unistd.h>) on Windows?

CodePudding user response:

Yes, if you setup WSL2, you should be able to develop C like you did on your VirtualBox machine. If decide to use Ubuntu, running sudo apt-get install build-essential should give you everything you need to compile and run C programs.

CodePudding user response:

It's called cross compiling. Using WSL(2) is kind of "overkill" for just building applications, but it makes testing the result a lot easier.

If all you're after is building, but not running the resulting executables, my suggestion would be MSys2 LLVM Clang. The nice thing about LLVM/Clang is, that it is always a "cross"-compiler; you can compile for every supported target on every supported host. https://clang.llvm.org/docs/CrossCompilation.html

There are also Linux targeting GCC builds available in MSys2, so that's an option, too.

  •  Tags:  
  • Related