Visual C + + for Linux development

Source: Internet
Author: User

Original Https://blogs.msdn.microsoft.com/vcblog/2016/03/30/visual-c-for-linux-development/Visual C + + for Linux Development

Today we ' re making a new extension available that enables C + + development in Visual Studio for Linux. With this extension you can author C + + code for Linux servers, desktops and devices. You can manage your connections to these machines from within VS. VS would automatically copy and remote build your sources and can launch your application with the debugger. Our project system supports targeting specific architectures, including ARM. Read on for what to get started with our new Linux projects.

Today we only have support for building remotely on the Linux target machine. We is not a limited by specific Linux distros and we do have a dependencies on the presence of some tools. Specifically, we need openssh-server, g++, GDB and Gdbserver. Use your favorite Package Manager to install them, e.g. on Debian based systems:

Su doapt-get install openssh-server g++ gdb gdbserver 
Installation

Download the Visual C + + for Linux development extension or get it from the extension Manager in Visual Studio. Today We do has a dependency on the Android Tools for Visual Studio. If you already has VS installed you can add those by going to add Remove Programs, modify Visual Studio and select them u NDEr Visual C + + Mobile development.

To get started create a new project by going to Templates > Visual C + + > Cross Platform > Linux .

Today We have three templates available; Blink for IoT devices like the Raspberry Pi, Console application as a bare application, and Empty for your to add sources a nd configure from a clean slate.

Your First VS Linux Project

Let's get started by creating a Console app. After creating your project from this template set a break point on the printf statement then hit F5 or the Remote GDB Deb Ugger button. By default, the Console application are set to a debug/x64 configuration. If your remote target is x86 or ARM you'll want to the change those options first. In this example I ' m using a x64 Ubuntu VM.

Since This was our first time targeting a Linux machine you'll be prompted for connection information. This was triggered by building the project.

We support both password and certificate base authorization, including use of passphrases with certificates. Upon a successful connection we save your connection information for subsequent connections. You can manage your saved connections underTools > Options > Cross Platform > Linux . Yes, passwords/passphrases is encrypted when stored. We plan to support connecting without saving the connection information in a future update.

Upon connecting, your sources would be copied to the remote Linux machine and we'll invoke GCC to build the sources with The options from the project properties. After the build successfully completes, your code would be a launched on the. You set earlier.

Linux Project Properties

Let's take a look at the project properties to understand where things got deployed on the remote Linux machine.

Under Remote settings, you'll see the remote root was set to ~/projects/by default and that we are setting the remote PR Oject directory to match our project name in this location. If we take a look at the Linux machine, we'll find main.cpp as well as our build artifacts in ~/projects/consoleapplicatio N1.

Looking at the general settings for the project, you can see how our output and intermediate directories were configured. Additionally, you'll see that the this project was configured as a Application–thus our executable is under bin/x64/debug/ As Consoleapplication1.out. Notice that for the configuration types we also support static and dynamic libraries.

Linux IoT Projects

Now let's take a look at a IoT device, the Raspberry Pi. You can use any type of Pi running Raspbian. For our blink sample, we use wiringpi–if you do not have the this setup you can either install it via apt or from source. To add a new connection, go to Tools > Options and search for Linux. Now click the add to connect to your Raspberry Pi.

Go to project properties and take a look under Build events at Remote post-build events.

You can use this to execute a command on the remote Linux target after build. This is a template comes preconfigured to export the GPIO pin for the LED so that we don't have to run our executable as root.

Now connect a LED to pin p your Raspberry Pi as shown here.

Open Main.cpp and set a breakpoint on the delay of the first digitalwrite and hit F5. You should see your LED lights up and execution would pause at your breakpoint. Step through your code over the next Digitalwrite call and you'll see your LED turn off.

Visit our IoT development page to stay the current "of our offerings in this space.

Desktop applications

We ' ve covered headless and device Linux applications, what's about desktop? Well, we had something special here:we ' re going to launch an OpenGL app on a Linux desktop. First make sure your Linux desktop have been configured for OpenGL development. Here is the apt packages we used:libgles1-mesa, Libgles1-mesa-dev, FREEGLUT3, Freeglut3-dev.

Now create a empty Linux project and go grab the source for Spinning Cube fromjulien guertault ' s OpenGL tutorial. Extract it and add main.c to your project. To enable Intellisense you'll need to add the OpenGL headers to the VC + + directories, you can get them from the OpenGL R  Egistry. Now go to your project properties and add export display=:0.0 to the pre-launch command.

Now, under Linker Input add the library DEPENDENCIES:M;GL; Glu;glut.

Also, make sure your remote settings is for the right machine.

Now hits F5.

A couple of interesting places to put breakpoints be around line in where the cube rotation is set (try changing the Alph A value) or in Keyboardfunc where can inspect the values of the pressed key.

Go Write Some Native Linux Code

We hope you is as excited by the possibilities this opens up as we are.

Install the Visual C + + for Linux development extension, try it off and let us know what works for you, what doesn ' t or if You encounter any issues. If your focus is the IoT remember to check out of our IoT development page to stay the current on happenings there. You can reach us here through the blog, on the extension page on the gallery, via the VS Feedback channel, or find our tea M @visualc or me, @robotdad, on Twitter.

–marc Goodner

Visual C + + for Linux development

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.