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.

Download the source code for this demonstration.

Create a New Project in Visual Studio

  1. In the New Project window, browse to the Templates–>Visual C++–>Cross Platform–>Linux node and choose the Empty Project (Linux) option, and name the project Hello World.

  2. Change the platform to ARM
  3. Add a new main.cpp source file.

  4. Add the following code to the main.cpp file. Unfortunately, Visual Studio does not know where to find the ComfilePi's header files, resulting in a number of errors.
#include <gtk/gtk.h>
int main(int argc, char *argv[])
	GtkWidget *window;
	gtk_init(&argc, &argv);
	window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
	printf("Running gtk_main\n");

There are many Intellisense errors because Visual Studio can't find the ComfilePi's header files.

Create a Samba Share for Header Files

To allow Visual Studio access to the ComfilePi's include folders, we will expose them through a Samba share.

  1. Be sure Samba is installed by running sudo apt-get install samba on the ComfilePi.
  2. Create a share for /usr, providing read-only access to /usr/include and /usr/lib, by editing the /etc/samba/smb.conf file as shown below
    read only=yes
    valid usr=pi
    hide dot files=yes
    follow symlinks=yes
    wide links=yes
    unix extensions=no

    See the smb.conf reference for more information.

  3. Restart the Samba server with sudo /etc/init.d/smbd restart
  4. Test access to the share on the Windows computer by opening \\{ComfilePI_IP_Address}\usr in Windows explorer.

Specify the Include Paths in the Project's Properties

Open the Project's Properties window.

  1. Replace the VC++ Directories–>Include Directories with the following:

    These includes are general C/C++ includes that will likely be needed for any C/C++ project.

  2. Replace the C/C++–>General–>Additonal Include Directories with the following:

    These includes are specific to this project due to the fact that it is using Gtk+. They can be determined by running pkg-config –cflags gtk+-2.0 on the ComfilePi.

    The project no longer shows any Intellisense errors.

  3. The procedure in step 2 will solve the Intellisense errors, but there will still be compiler and linker errors when the project is compiled. To resolve those errors, add `pkg-config –cflags gtk+-2.0` to the C/C++–>Command Line–>Additional Options setting, and add `pkg-config –libs gtk+-2.0` to the Linker–>Command Line–>Additional Options setting.

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 the Remote GDB Debugger. The source code will be uploaded to the ComfilePi to be built.

    The first time, a Connect to Remote System dialog window may appear. Enter the IP address of the ComfilePi in the Host name field and enter the ComfilePi's user credentials.

    The settings can be changed in the Configuration Properties–>General–>Remote Build Machine setting.

  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 statements.

comfilepi/create_a_linux_project/index.txt · Last modified: 2019/03/05 16:08 by COMFILE Technology