简体   繁体   中英

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

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 (eg: <unistd.h>) on Windows?

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM