User Tools

Site Tools



Create a Visual C++ Linux Project In Visual Studio

The Visual Studio Linux Features do not inherently support cross-compiling on a Windows PC. Instead, Visual Studio will upload the the source files to the ComfilePi, and use the ComfilePi's toolchain to build the executable. The executable is then executed on the ComfilePi, and the Visual Studio Remote GDB Debugger attaches to it.

This method can be used for much more than console applications, including Qt, GTK+, and even OpenGL to name a few. The demonstration that follows illustrates that development process for very simple GTK+ GUI application.

To utilize this example, please be sure to install the GTK development tooling to the ComfilePi panel PC using the command sudo apt install libgtk-3-dev.

Download the source code for this demonstration.

Create a New Project in Visual Studio

  1. Open Visual Studio to create a new project.

  2. Use the Empty Project template, but others are also possible.

  3. Change the platform to ARM or ARM64 per the ComfilePi OS variant that you are using.
  4. Use the Connection Manager to establish an SSH connection with the target ComfilePi panel PC.

  5. Add a new main.cpp source file with the following code.
#include <gtk/gtk.h>
static void print_hello(GtkWidget* widget, gpointer data)
    g_print("Hello World\n");
static void activate(GtkApplication* app, gpointer user_data)
    GtkWidget* window;
    GtkWidget* button;
    GtkWidget* button_box;
    window = gtk_application_window_new(app);
    gtk_window_set_title(GTK_WINDOW(window), "Window");
    gtk_window_set_default_size(GTK_WINDOW(window), 200, 200);
    button_box = gtk_button_box_new(GTK_ORIENTATION_HORIZONTAL);
    gtk_container_add(GTK_CONTAINER(window), button_box);
    button = gtk_button_new_with_label("Hello World");
    g_signal_connect(button, "clicked", G_CALLBACK(print_hello), NULL);
    g_signal_connect_swapped(button, "clicked", G_CALLBACK(gtk_widget_destroy), window);
    gtk_container_add(GTK_CONTAINER(button_box), button);
int main(int argc, char** argv)
    GtkApplication* app;
    int status;
    app = gtk_application_new("org.gtk.example", G_APPLICATION_FLAGS_NONE);
    g_signal_connect(app, "activate", G_CALLBACK(activate), NULL);
    status = g_application_run(G_APPLICATION(app), argc, argv);
    return status;

There will be many Intellisense errors because we haven't yet updated the include paths for GTK.

Specify the Include Paths in the Project's Properties

Open the Project's Properties window.

  1. Modify the C/C++–>General–>Additional Include Directories with the following:
    /usr/include/gtk-3.0;/usr/include/at-spi2-atk/2.0;/usr/include/at-spi-2.0;/usr/include/dbus-1.0;/usr/lib/aarch64-linux-gnu/dbus-1.0/include;/usr/include/gtk-3.0;/usr/include/gio-unix-2.0;/usr/include/cairo;/usr/include/pango-1.0;/usr/include/fribidi;/usr/include/harfbuzz; /usr/include/atk-1.0;/usr/include/cairo;/usr/include/pixman-1;/usr/include/uuid;/usr/include/freetype2;/usr/include/libpng16;/usr/include/gdk-pixbuf-2.0;/usr/include/libmount;/usr/include/blkid;/usr/include/glib-2.0;/usr/lib/aarch64-linux-gnu/glib-2.0/include

    These includes can be determined by running pkg-config --cflags gtk+-3.0 on the ComfilePi. After adding the additional include paths, there should no longer be any Intellisense errors.

Specify the Library Depenencies in the Project's Properties

  1. The prior step will solve the Intellisense errors, but there will still be linker errors when the project is compiled. To resolve those errors, add the following library dependencies.

Those library dependencies can be obtained by running pkg-config --libs gtk+-3.0 on the ComfilePi.

If you encounter any Intellisense errors, try synchronizing Visual Studio's copy of the ComfilePi's header files in Tools–>Options–>Cross Platform–>Connection Manager–>Remote Headers Intellisense Manager by selecting the appropriate connection and pressing the Download or Update button.

Deploy, Build, and Degug

  1. Add export DISPLAY=:0.0 to the Configuration Properties–>Debugging–>Pre-Launch Command setting so the ComfilePi knows which display to show the window on.

  2. Start debugging. The source code will be uploaded to the ComfilePi to be built.

  3. If no build errors are encountered, the program will execute on the ComfilePi, and the Visual Studio Remote GDB Debugger will attach to it. Go to Debug–>Linux Console to display the Linux Console Window and view any messages from printf and/or gprint statements.

Additional Resources

  • Install GTK examples with `sudo apt install gtk-3-examples`. The examples will be installed to /usr/share/doc/gtk-3-examples/examples
  • Use the Glade on a Linux PC to create a GUI using a WYSIWYG designer.
comfilepi/create_a_linux_project/index.txt · Last modified: 2023/03/13 13:27 by COMFILE Technology