Visual C++ for Linux Development

原文  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 will 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 how to get started with our new Linux projects.

Today we only support building remotely on the Linux target machine. We are not limited by specific Linux distros but we do have 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:

sudo apt-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 have a dependency on the Android Tools for Visual Studio. If you already have VS installed you can add those by going to Add Remove Programs, modify Visual Studio and select them under 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 you to add sources and configure from a clean slate.

Your First VS Linux Project

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

Since this is our first time targeting a Linux machine you will be prompted for connection information.  This is 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 are encrypted when stored. We plan to support connecting without saving the connection information in a future update.

Upon connecting, your sources will be copied to the remote Linux machine and we will invoke gcc to build the sources with the options from the project properties. After the build successfully completes, your code will be launched on the remote machine and you will hit the break point 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 will see the remote root is set to ~/projects/ by default and that we are setting the remote project directory to match our project name in that location. If we take a look on the Linux machine, we’ll find main.cpp as well as our build artifacts in ~/projects/ConsoleApplication1.

Looking at the General settings for the project, you can see how our output and intermediate directories were configured. Additionally, you’ll see that this project was configured as an application – thus our executable is under bin/x64/Debug/ as ConsoleApplication1.out. Notice that for configuration types we also support static and dynamic libraries.

Linux IoT Projects

Now let’s take a look at an IoT device, the Raspberry Pi. You can use any type of Pi running Raspbian. For our blink sample we use wiringPi – if you don’t have 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 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 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 an LED to pin 17 on your Raspberry Pi as shown here.

Open main.cpp and set a breakpoint on the delay call after the first digitalWrite and hit F5. You should see your LED light up and execution will pause at your breakpoint. Step through your code over the next digitalWrite call and you will see your LED turn off.

Visit our IoT Development page to stay current on all of our offerings in this space.

Desktop Applications

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

Now create an 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 will need to add the OpenGL headers to the VC++ Directories, you can get them from the OpenGL Registry .  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 are for the right machine.

Now hit F5.

A couple of interesting places to put breakpoints are around line 80 where the cube rotation is set (try changing the alpha value) or in KeyboardFunc where you can inspect the values of the pressed key.

Go Write Some Native Linux Code

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

Install the Visual C++ for Linux Development extension , try it out and let us know what works for you, what doesn’t or if you encounter any issues. If your focus is IoT remember to check out our IoT Development page to stay 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 team @visualc  or me,  @robotdad , on Twitter.

– Marc Goodner

时间: 2024-10-31 18:38:26

Visual C++ for Linux Development的相关文章

通过 Visual Studio 为 Linux 编写 C++ 代码

Build 2016大会上Microsoft首次公布的Visual Studio 2015扩展提供了在VS2015中编写C++代码,随后通过Linux/UNIX计算机进行编译和执行的能力.这种想法非常简单:使用Visual Studio 2015编写和开发C++代码,然后将代码部署到运行Linux的远程计算机上进行编译和调试. 该扩展可在运行Windows的计算机和运行g++编译器的远程计算机之间通过SSH进行通信.这意味着虽然该扩展本身是"针对Linux"构建 的,实际上除了在Lin

[转]通过Visual Studio为Linux编写C++代码

Build 2016大会上Microsoft首次公布的Visual Studio 2015扩展提供了在VS2015中编写C++代码,随后通过Linux/UNIX计算机进行编译和执行的能力.这种想法非常简单:使用Visual Studio 2015编写和开发C++代码,然后将代码部署到运行Linux的远程计算机上进行编译和调试. 该扩展可在运行Windows的计算机和运行g++编译器的远程计算机之间通过SSH进行通信.这意味着虽然该扩展本身是"针对Linux"构建的,实际上除了在Linu

Linux 工程师新法宝:在 Visual Studio 上用 C++ 写 Linux

如今我们正在开发一个新的插件,一个能够让开发者在 Visual Studio (以下简称 VS ) 上建构能够在 Linux 上运行 C++ 程序的套件.开发者可以借由这个插件将 C++ 程序移转到 Linux 服务器.PC 以及移动设备上,也同时可以借由这个插件将这些机器连结至你的 VS 上. VS 将会自动地复制一份并在远端建构你的来源档,再运行带有除错器的应用程序.我们的这项计划也针对特殊的架构提供系统支持,包含 ARM 等. 下方文章将继续介绍使用我们这套全新的 Linux 计划. 目前

Visual Studio 2015 for Linux更好地支持Linux下的开发

Visual C++ for Linux扩展使Visual Studio 2015的用户可以在VS2015中编写C或者C++代码,并将代码部署到基于Linux的系统中去编译和调试.源代码和项目文件通过SSH传输到远程机上,程序的输出将显示在Visual Studio上. Microsoft的Marc Goodner分享了更多有关新版本(1.0.5)的发布细节,据他所述,新版本在以下的几个领域中提供了新的功能:makefile项目模板.远程源复制管理.可重写的C/C++编译器路径以及新的调试选项.

性能: 使用Visual Studio分析器找出应用程序瓶颈

本文讨论: 以性能瓶颈为目标 应用程序代码分析 比较分析数据 性能报告 本文使用了以下技术: Visual Studio 2008 在过去十年间,涌现了许多新的软件技 术和平台.每种新技术都要求掌握专门的知识才能创建出性能良好的应用程序.现在,由于各种 Internet 技术(如博客)使失望的用户可轻松地否定您的应用程序,因此您确实需要将性能放到首要位 置.在计划早期,就应添加响应性能要求并创建原型来确定可能的技术限制.在整个开发过程中,还应衡 量应用程序的各个性能方面以发现可能的性能下降,同时

快速配置 Samba 将 Linux 目录映射为 Windows 驱动器

原文链接 samba client ubuntu redhat ubuntu gui tools  1,列出某个IP地址所提供的共享文件夹 smbclient -L 198.168.0.1   2,在security=share模式下访问一个匿名可以访问的目录 smbclient //192.168.0.1/目录名 3,像FTP客户端一样使用smbclient smbclient //192.168.0.1/tmp  -U username%password  4,例,创建一个共享文件夹 smb

使用 Visual Studio 分析器找出应用程序瓶颈

在过去十年间,涌现了许多新的软件技术和平台.每种新技术都要求掌握专门的知识才能创建出性能良好的应用程序.现在,由于各种 Internet 技术(如博客)使失望的用户可轻松地否定您的应用程序,因此您确实需要将性能放到首要位置.在计划早期,就应添加响应性能要求并创建原型来确定可能的技术限制.在整个开发过程中,还应衡量应用程序的各个性能方面以发现可能的性能下降,同时确保速度较慢情形下的测试人员文件并跟踪其错误. 即使拥有最好的计划,仍必须在产品开发过程中调查性能问题.在本文中,我们将向您展示如何使用

在Ubuntu中安装Visual Studio Code

在Ubuntu中安装Visual Studio Code 微软令人意外地发布了Visual Studio Code,并支持主要的桌面平台,当然包括linux.如果你是一名需要在ubuntu工作的web开发人员,你可以非常轻松的安装Visual Studio Code. 我将要使用Ubuntu Make来安装Visual Studio Code.Ubuntu Make,就是以前的Ubuntu开发者工具中心,是一个命令行工具,帮助用户快速安装各种开发工具.语言和IDE.也可以使用Ubuntu Mak

Linux学习基础_unix linux

      1.什么是Linux? 准确的说,是指Linux的kernel(系统的核心程序),其内核版权属于Linus Torvalds,在GPL(GNU General Public License)版权协议下发行, 任何人都可以自由的复制(copy), 修改(change), 套装分发(distribute),销售,但是不可以在分发时加入任何限制, 而且所有原码必须是公开的,所以任何人都可以无偿取得所有执行文件和原代码. 对于Linux用户和系统管理员来说,Linux是指包含Linux ke