Importing Cygwin-based Projects to Visual Studio

This tutorial shows how to import existing cygwin-based projects to Visual Studio. We will download the sources for the GNU diffutils package, configure it with cygwin and use Visual Studio to build and debug them.

Before you begin, please install Cygwin and VisualGDB.

  1. To fetch the source archive, open Cygwin installer, find the diffutils package and check the “Source” checkbox.01-diffutils
  2. When the installation completes, the source package will be automatically extracted to /usr/src/diffutils-<version>. Please start cygwin shell, go to the diffutils directory and configure them by typing the following command:
    ./configure
  3. Now open Visual Studio, select File->New->Project and choose VisualGDB wizard:03-newprj
  4. In the VisualGDB wizard select “Windows Application”04-windows
  5. On the next page select “Import existing” and specify the directory where you have configured diffutils.05-importdir
  6. The next page allows to choose whether you want to import the source files into the Solution Explorer. This will make Visual Studio parse them with IntelliSense so that the Go To Definition function will work, but might take some time. Importing files to Solution Explorer does not affect building or debugging. In this tutorial we will choose the first option:05b-importdir
  7. On the next page select “Cygwin” as the toolchain.06-toolchain
  8. Ensure that the “Project is based on GNU Make” checkbox got selected automatically. If not, you have either selected a wrong directory, or the configure script has failed to create the Makefile.07-import
  9. This page allows selecting the application to debug. As we don’t know the exact path right now, just enter “diff.exe”. We will change it later. Press Finish.09-debug
  10. The next page allows setting custom path mapping for error messages. You don’t need to change anything here now.08-pathmap
  11. When the project is created, build it by pressing Ctrl+Shift+B in Visual Studio. If you get any errors, Visual Studio will show them in the Errors window.
  12. In order to find out the name of the EXE file, run the following command in the directory that you have specified when importing the project:
    find -name *.exe

    10-names

  13. We will debug diff.exe, thus the relative path is src/diff.exe
  14. Go back to Visual Studio, right-click at the project and select VisualGDB Project Properties:11-properties
  15. Enter the relative path to the debugged executable (src/diff.exe) to the “Main Binary” field. Just to run a simple test, we will let diff.exe compare the /etc/hosts file to itself. Enter the following arguments in the “Main executable arguments” field:
    /etc/hosts /etc/hosts

    12-args

  16. Open the “diff.c” file and put a breakpoint on the diff_main() function. Then select Debug->Start Debugging with GDB:13-dbgstart
  17. When the breakpoint is hit, you can inspect the values of argv[] array by using GDB array syntax. Enter the following expression to the watch window:
    *argv@3

    14-argv

  18. Visual Studio will show you the diff path and both arguments exactly as GDB reports it.
  19. You can now set breakpoints, step through your program and use any other Visual Studio debugging techniques. To stop debugging, press Shift-F5.