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.

  1. Start Visual Studio. Select File->New->Project. Locate the VisualGDB Linux Project wizard:01-prjname

  2. On the first page of the wizard select “Application” and proceed to the next page:02-app

  3. 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:03-target

  4. When you press “next” VisualGDB will test the compiler/linker on your FreeBSD machine:04-test

  5. The last page of the wizard allows configuring the location where your source code will be uploaded. You can proceed with the default settings:05-source

  6. Press “Finish” to generate your project. VisualGDB will automatically download the include files and configure IntelliSense to use them:06-includes

  7. 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:07-builderr

  8. 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':08-gmake

  9. Now you can build your project by pressing Ctrl-Shift-F5:09-buildok

  10. 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:10-oldgdb

  11. 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:11-getgdb

  12. Go to VisualGDB Project properties and set the custom GDB executable to the one you have installed:12-gdb762

  13. Now you can debug your application using all the features of modern GDB that are available on FreeBSD:13-newgdb

  14. 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:14-signals

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.