Creating MinGW64 applications with Visual Studio

This tutorial shows how to create a MinGW64-based application with Visual Studio and debug it with VisualGDB.

  1. Download and install VisualGDB. Open Visual Studio, select File->New Project->VisualGDB and pick the MinGW/Cygwin project wizard:
  2. On the first page of the wizard select Create a new Project => Application. VisualGDB can create MinGW64 projects using either GNU Make, or CMake. In this tutorial we will show the more advanced CMake option. Select CMake, Ninja and check the “Advanced CMake project Subsystem” checkbox:
  3. If you have not installed MinGW64 yet, select the auto-download option from the list:
  4. Once the toolchain is installed it will appear in the normal toolchain list in the wizard. Press Finish to complete the wizard and wait for VisualGDB to test the toolchain consistency:
  5. Your Visual Studio project will be now created. Press Ctrl-Shift-B to build it.
  6. Now we will show how to add new code to the project using the Advanced CMake Project Subsystem and Clang IntelliSense. Right-click on the executable node in Solution Explorer and select Add->New Item:
  7. Pick “Source file” and specify the name for the new file:
  8. VisualGDB will create the new source file and will automatically update the add_executable() statement in the CMakeLists.txt file:
  9. Follow a similar procedure to create a header file and add an empty class in it. VisualGDB will warn that the header is not included from any source files yet and hence IntelliSense won’t be accurate:
  10. Go to the main C++ source file, include the header file, create an instance of the new class and finally try calling a non-existing method from it. Press Ctrl+. to display VisualGDB’s suggestion to generate a new function/method:
  11. VisualGDB will try to guess the argument values and return value based on the context of the call. In this example, the return value is incorrectly guessed as std::ostream:
  12. Change the return value to int and add a basic implementation to the method. Then select “Implementation: in source file” and press Ctrl-Enter to complete the edit:
  13. VisualGDB will automatically create the new method:
  14. Set a breakpoint in the add() method and press F5 to start debugging. The breakpoint will now trigger:
  15. You can use the GDB Session window to see the commands sent by VisualGDB to the gdb debugger and run your own gdb commands:
  16. You can also quickly explore the relations between different parts of your program using CodeJumps (clickable links above the function names). Use the tag icon in the top right corner of the source editor to quickly toggle the display of CodeJumps labels: