This article is useful if you want to compile for Linux without having to use Linux, either because you don't like its interface or because an IDE you use is not available on this system, or for another reason; this article is also useful if you want to test Linux without having to install it.
Install and Configure Linux
First, you install Linux on Windows (by the Microsoft Store).1 I chose Debian.
It is very easy to configure Debian.
GUI
Run the commands below to enable the GUI:
sudo apt update
sudo apt upgrade
sudo apt-get install xrdp
After you execute the last command, you'll see the below screen:
And one of the commands below (the first to install Xfce4 and the second to install LXDE):
sudo apt-get install xfce4
sudo apt-get install lxde
Every time you want to use the GUI, you have to run the command below and then open the Remote Desktop and connect to the localhost:3390.
sudo /etc/init.d/xrdp start
To make this command permanent, run the command below inside the ~ directory and go to the end.
sudo nano .bashrc
Now you add the lines below, press Ctrl + X, press Y and after press Enter and restart.
sudo /etc/init.d/xrdp start
clear
And so as not to have to enter your username and password every time, click on Show Options on the Remote Desktop screen and in user name, write the user name of your distribution and check to allow saving my credentials.
After you click on connect, the following window will appear:
In that window, click on more options, use a different account, fill in the username and password fields with the username and password of the distribution you chose and click OK.
In case of error, run the command below, change port=3389 (probably in line 8) to port=3390, press Ctrl + X, press Y and after press Enter and restart.
sudo nano /etc/xrdp/xrdp.ini
To restart, run the command below:
sudo /etc/init.d/xrdp restart
Debian with Xfce working:
Debian with LXDE working:
Compile C and C++ for Linux
First, you need to install the gcc and g++, for this, run the commands below:
sudo apt-get install gcc
sudo apt-get install g++
And to compile C on Linux to Linux:
gcc program.c -o program
Where program.c is the file name and program is the program name.
And C++:
g++ program.cpp -o program
Where program.cpp is the file name and program is the program name.
If you want to make this on Windows (Command Prompt), you add the prefix "distribution run" where distribution is the distribution name.
Example:
I want to compile the file ddd.cpp in Windows with Debian. I run:
debian run g++ ddd.cpp -o ddd
And to run the program on Debian:
./program
Where program is the program name.
And to run on Windows (Command Prompt):
debian run ./program
Where program is the program name.
Notes
1 It cannot be Ubuntu or openSUSE if you want to use the GUI.
History
- 22nd January, 2020: Initial version
- 18th Febuary, 2020: Second version
Read My Other Articles
If you have any comments, please leave a note below.