installing netbeans ide for use with wsl and...
TRANSCRIPT
version 1.0 page 1
Installing NetBeans IDE for use with WSL and C++ (version 1.0)
This set of instructions assumes that you have already installed WSL (Windows Subsystem for Linux)
along with gcc, g++, make, and gdb.
This set of instructions is for WSL ONLY! These instructions do not apply to Cygwin or Linux distributions
in general.
NetBeans does not currently (as of version 8.2) automatically recognize the gnu compilers installed in
WSL. However, you can use the WSL gnu compilers from NetBeans as a “remote host”. This is a process
where you use NetBeans on your local machine to edit code and use a remote host to compile and run
the code. In this case, Windows will be your local machine and WSL will be the remote host even though
both are running on the same computer.
Prepare WSL as a Remote Host
1. Update the Linux packages being used by WSL with the following commands in your WSL
Ubuntu command window:
sudo apt update
sudo apt upgrade
2. The following instructions assume you will use the nano text editor to modify a text file. A nano tutorial is available at: https://www.howtogeek.com/howto/42980/the-beginners-guide-to-nano-the-linux-command-line-text-editor/ Your Windows installation is probably already using port 22 for its SSH server, we need to change WSL’s SSH server to listen to a different port. sudo nano /etc/ssh/sshd_config Change the lines:
# What ports, IPs and protocols we listen for Port 22
to Port 2222
The WSL SSH server is initially set up to use key files for authentication. To allow authentication
with passwords, change:
# Change to no to disable tunnelled clear text passwords PasswordAuthentication no
to PasswordAuthentication yes
Use Ctrl-o to save the file. Use Ctrl-x to exit the nano text editor.
version 1.0 page 2
3. NetBeans will transfer the source code files in your project as a zip file. Install unzip in WSL using
the following command:
sudo apt install unzip
4. Before using the WSL SSH server you must stop and restart the SSH server. You will perform this
step every time that you use WSL as the remote host from NetBeans. I suggest placing the
command in a script file that you can execute.
nano startssh.sh
Insert the following text into the script file:
sudo service ssh --full-restart
Use Ctrl-o to save the file. Use Ctrl-x to exit the nano text editor.
Back at the command line, use the following command to mark the script file as executable:
chmod a+x startssh.sh
To restart the SSH server, use the following command:
./startssh.sh
version 1.0 page 3
Install NetBeans for Use with C/C++
5. Download and install the NetBeans IDE Bundle for C/C++: https://netbeans.org/downloads/
(Note: If you already use the NetBeans IDE for Java or PHP, you can install the C/C++ plugin from
the Tools > Plugins menu.)
6. Use the menu Tools > Plugins to update all plugins
7. Next you will configure the Build Host for C++. Access the options pane with the menu
Tools > Options > C++
Click Edit for Build Hosts
version 1.0 page 4
8. Click Add…
9. Enter localhost as the Hostname and 2222 as the port. Then click Next > .
10. Enter your WSL username as the Login and click Next > .
11. Enter your password into the dialog box. I suggest selecting Remember Password . Click OK .
version 1.0 page 5
12. NetBeans will now login to the “remote host” and search for the compiler tools.
13. Once NetBeans finishes its search, it will display what type of tools that it found. Click Finish .
14. Select your WSL entry as the default Build Host.
version 1.0 page 6
15. Now gcc, g++, make, and gdb should be shown as the build tools being used by NetBeans. Click
the Other tab.
16. Make sure that C++11 is the Default Standard for C++ Headers and Files. Click OK .
version 1.0 page 7
Creating a C/C++ Project The preceding steps (Prepare WSL as a Remote Host and Prepare WSL as a Remote Host) are only
needed once. The following instructions are to be followed any time you create a new C/C++ project.
1. Use the menu File > New Project… to open the New Project dialog window.
Select C/C++ Project with Existing Sources and click Next > .
2. Use the Browse… button to bring up a file browser.
version 1.0 page 8
3. Select the directory that holds your source code and makefile. Click Select .
4. Click Finish to create the project.
version 1.0 page 9
5. Open a source code file by double-clicking it in the Projects Tab. Build the project by clicking the
Hammer button. Run the project by clicking the Green Arrow button.
6. The first time the project is run, NetBeans will ask you for the executable file. It is usually
automatically selected by NetBeans correctly.
version 1.0 page 10
7. You will interact with the running program through the Output window.
8. To debug your project, set a breakpoint by clicking on a line number. Then use the debug
button to start the execution.
NetBeans provides a tutorial on debugging C/C++ programs:
https://netbeans.org/kb/docs/cnd/debugging.html
version 1.0 page 11
References
https://netbeans.org/bugzilla/show_bug.cgi?id=267478
https://superuser.com/questions/1111591/how-can-i-ssh-into-bash-on-ubuntu-on-windows-10
https://blogs.msdn.microsoft.com/vcblog/2017/02/08/targeting-windows-subsystem-for-linux-from-
visual-studio/
The latest version of this document is available at:
http://cse.msstate.edu/~crumpton/reference/