Using Visual Studio to develop for FreeBSD
This tutorial shows how to create a basic FreeBSD command-line application with VisualGDB. FreeBSD is supported by the Linux Edition of VisualGDB, but requires some extra steps to configure due to differences between Linux and FreeBSD.
-
Start Visual Studio. Select File->New->Project. Locate the VisualGDB Linux Project wizard:
-
On the first page of the wizard select “Application” and proceed to the next page:
-
On the second page of the wizard select your FreeBSD machine. Note that you need to have the SSH server running there in order to connect using VisualGDB:
-
When you press “next” VisualGDB will test the compiler/linker on your FreeBSD machine:
-
The last page of the wizard allows configuring the location where your source code will be uploaded. You can proceed with the default settings:
-
Press “Finish” to generate your project. VisualGDB will automatically download the include files and configure IntelliSense to use them:
-
If you try building your project now, make will report numerous errors. This happens because VisualGDB generates a Makefile that relies on various features of GNU make and FreeBSD by default uses the original BSD make lacking many of those features:
-
To fix Makefile issues, go to your FreeBSD machine and install the GNU make by running the following command:
pkg install gmake
Then go to VisualGDB Project Properties and change ‘make’ to ‘gmake’:
-
If you press F5 now, debugging will most likely start normally, but VisualGDB will warn that you are using a very old gdb version and many features will not work:
-
Thankfully there is a very simple solution to this problem. Run “pkg install gdb” to get the latest version of GDB. Note that the new gdb will be available as “gdbxyz” where x.y.z is its version:
-
Go to VisualGDB Project properties and set the custom GDB executable to the one you have installed:
-
Now you can debug your application using all the features of modern GDB that are available on FreeBSD:
-
Note that signal handling on FreeBSD is slightly different from the signal handling on Linux. If you want to modify the way gdb handles the signals, you can use the “Signals & Catchpoints” button in the GDB Session window:
That’s it. Now you can go ahead and develop your application. Note that many of the Linux features described on our Linux tutorials will also work on FreeBSD.