Click here to Skip to main content
15,918,193 members
Articles / Programming Languages / C
Tip/Trick

Linux on Windows

Rate me:
Please Sign up or sign in to vote.
4.97/5 (19 votes)
24 Oct 2022CPOL2 min read 60.6K   657   49   41
How to use WSL, GUI on WSL and how to compile for Linux on Windows
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.

Download Debian

It is very easy to configure Debian.

GUI

Run the commands below to enable the GUI:

BAT
sudo apt update
sudo apt upgrade
sudo apt-get install xrdp

After you execute the last command, you'll see the below screen:

Configuring Xfce

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.

BAT
sudo /etc/init.d/xrdp start

Remote Desktop

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

Modifying .bashrc

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.

How to make the GUI automatic

After you click on connect, the following window will appear:

How to make the GUI automatic (the second window)

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.

BAT
sudo nano /etc/xrdp/xrdp.ini

In case of error

To restart, run the command below:

BAT
sudo /etc/init.d/xrdp restart

Debian with Xfce working:

Debian working with Xfce

Debian with LXDE 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:

BAT
sudo apt-get install gcc
sudo apt-get install g++

And to compile C on Linux to Linux:

BAT
gcc program.c -o program

Where program.c is the file name and program is the program name.

And C++:

BAT
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:

BAT
debian run g++ ddd.cpp -o ddd

And to run the program on Debian:

BAT
./program

Where program is the program name.

And to run on Windows (Command Prompt):

BAT
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.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Brazil Brazil
I'm a student of programming and math, a chess player and a person who by nature loves to solve problems

Comments and Discussions

 
QuestionNice Pin
Jeremy Falcon26-Oct-22 10:58
professionalJeremy Falcon26-Oct-22 10:58 
QuestionI have noted one change Pin
E. Wilcox18-Apr-20 7:29
E. Wilcox18-Apr-20 7:29 
AnswerRe: I have noted one change Pin
Tiago Cavalcante Trindade15-Jun-20 7:04
Tiago Cavalcante Trindade15-Jun-20 7:04 
QuestionActually got it working with Ubuntu Pin
alleyes4-Mar-20 8:54
professionalalleyes4-Mar-20 8:54 
AnswerRe: Actually got it working with Ubuntu Pin
Tiago Cavalcante Trindade4-Mar-20 13:24
Tiago Cavalcante Trindade4-Mar-20 13:24 
GeneralRe: Actually got it working with Ubuntu Pin
alleyes4-Mar-20 13:35
professionalalleyes4-Mar-20 13:35 
QuestionGreat article - xrdp doesn't launch Pin
alleyes21-Feb-20 3:38
professionalalleyes21-Feb-20 3:38 
AnswerRe: Great article - xrdp doesn't launch Pin
Tiago Cavalcante Trindade22-Feb-20 2:49
Tiago Cavalcante Trindade22-Feb-20 2:49 
AnswerRe: Great article - xrdp doesn't launch Pin
alleyes24-Feb-20 2:32
professionalalleyes24-Feb-20 2:32 
GeneralRe: Great article - xrdp doesn't launch Pin
Pete Lomax Member 1066450526-Feb-20 4:14
professionalPete Lomax Member 1066450526-Feb-20 4:14 
GeneralRe: Great article - xrdp doesn't launch Pin
alleyes26-Feb-20 4:16
professionalalleyes26-Feb-20 4:16 
Yessir!
GeneralRe: Great article - xrdp doesn't launch Pin
alleyes26-Feb-20 4:20
professionalalleyes26-Feb-20 4:20 
GeneralRe: Great article - xrdp doesn't launch Pin
Pete Lomax Member 1066450526-Feb-20 7:04
professionalPete Lomax Member 1066450526-Feb-20 7:04 
GeneralRe: Great article - xrdp doesn't launch Pin
alleyes26-Feb-20 7:28
professionalalleyes26-Feb-20 7:28 
AnswerRe: Great article - xrdp doesn't launch Pin
Tiago Cavalcante Trindade26-Feb-20 22:10
Tiago Cavalcante Trindade26-Feb-20 22:10 
GeneralRe: Great article - xrdp doesn't launch Pin
alleyes27-Feb-20 1:11
professionalalleyes27-Feb-20 1:11 
QuestionWeb Browser don't work on XFCE4? Pin
snoopy00121-Feb-20 2:04
snoopy00121-Feb-20 2:04 
AnswerRe: Web Browser don't work on XFCE4? Pin
magemaster21-Feb-20 8:57
magemaster21-Feb-20 8:57 
GeneralRe: Web Browser don't work on XFCE4? Pin
snoopy00121-Feb-20 13:03
snoopy00121-Feb-20 13:03 
GeneralRe: Web Browser don't work on XFCE4? Pin
Tiago Cavalcante Trindade22-Feb-20 8:02
Tiago Cavalcante Trindade22-Feb-20 8:02 
AnswerRe: Web Browser don't work on XFCE4? Pin
Tiago Cavalcante Trindade22-Feb-20 8:03
Tiago Cavalcante Trindade22-Feb-20 8:03 
GeneralRe: Web Browser don't work on XFCE4? Pin
alleyes24-Feb-20 2:33
professionalalleyes24-Feb-20 2:33 
GeneralThis is working well for me Pin
E. Wilcox11-Feb-20 9:14
E. Wilcox11-Feb-20 9:14 
GeneralRe: This is working well for me Pin
Tiago Cavalcante Trindade16-Feb-20 11:16
Tiago Cavalcante Trindade16-Feb-20 11:16 
GeneralRe: This is working well for me Pin
E. Wilcox17-Feb-20 11:05
E. Wilcox17-Feb-20 11:05 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.