目前我们正在开垦贰个新的插件,三个可见让开荒者在 Visual Studio (以下简单的称呼VS 卡塔尔 上建设布局能够在 Linux 上运维 C++ 程序的套件。开荒者能够借由这几个插件将
C++ 程序移转到 Linux 服务器、PC
以至移动设备上,也同一时候能够借由那一个插件将这一个机器连结至你的 VS 上。

微软前些天在官方MSDN博客上发布公文表示他们正在开辟三个新的插件,一个力所能致让开采者在Visual
Studio上营造能够在Linux上运营C++程序的套件。开辟者可以借由这么些插件将C++程序移植到Linux服务器、PC以至运动设备上,也还要能够借由那一个插件将那一个设施连接至VS。看见那个音讯,网上朋友纷繁表示,Visual
Studio果然是大自然第一IDE!

原文  https://blogs.msdn.microsoft.com/vcblog/2016/03/30/visual-c-for-linux-development/

在 Linux 上支付 C/C++ 程序,可能你会一向(本机或远端)登入Linux,展开编辑器写完代码后,就用 gcc/g++
来编写翻译,遭遇要除错(debug)的时候,则会采纳使用 gdb
来拓展除错。现在,假诺您适逢其时也很疼爱 Visual
Studio,你可以不要更改习于旧贯,用 Visual
Studio写程式、然后远端送到
Linux 上编译、以致仍然是能够接上 gdb
来除错。那么些对于开发疑似嵌入式系统、或是 IoT
装置的主次等等就足以多Dolly用 Visual Studio 强盛的 IDE 本领。

VS
将会自行地复制一份并在远端营造你的来源档,再运营带有除错器的应用程序。大家的那项布置也本着出色的构造提供系统帮忙,富含ARM 等。

微软还在博客中详细介绍了该类型的应用办法,感兴趣可观察如下原文

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

图片 1

红尘小说将一连介绍使用我们那套全新的 Linux 布置。

日前大家仅扶持在远端的靶子Linux机器提供创建服务。我们并未限定特定的Linux揭橥版本,但大家还是在有个别工具的显现上有一点点相依性的歧异。须要非常注意的是,我们要求openssh-server、g++、gdb以至gdbserver。用你最习于旧贯的套件管理工科具来安装他们,比如在Debian类型的Linux就足以应用:

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
 .

图片 2

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.

图: 应该有成千上万在 Linux 上写程式的开采职员是那般职业的吗?

当前我们仅协助在远端的对象 Linux 机器提供建立服务。大家并不曾界定特定的
Linux
公布版本,但大家还是在有的工具的显现上某些相依性的差别。要求极其注意的是,大家须求openssh-server、g++、gdb 以及gdbserver。用你最习贯的套件管理工科具来设置他们,举个例子在 Debian 类型的
Linux 就可以运用:

sudo apt-get install openssh-server g++ gdb gdbserver

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.

图片 3

Since this is our first time targeting a Linux machine you will be
prompted for connection information.  This is triggered by building the
project.

图片 4

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.

图片 5

  如何做?

sudo apt-get install openssh-server g++ gdb gdbserver

安装

Linux Project Properties

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

图片 6

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.

图片 7

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.

  首先,你必须要选取 Visual Studio 二〇一五,你能够应用免费版[1]的 Visual
Studio 二零一四 Community 或是别的更加高阶段的本子,记得在装置时要勾选 Visual
C++ 以至 C++
跨平台行动付出那七个零件:

安装

下载 Visual C++ for Linux Development
extension 或从 Visual Studio
上的插件管理员来博取。近些日子我们在 Visual Studio 上的 Android Tools
樱笋时有相依协理。借令你已经安装了 VS 的话,你能够借由 Add Remove Programs
来新添那几个效应,编辑 VS 然后在 Visual C++ 移动设备开垦下抉择他们。

要初步一个新的类别可以因而以下路子:Templates > Visual C++ > CrossPlatform > Linux。

图片 8

脚下大家有四个能够行使的模板:针对像 Raspberry Pi 等物联网装置设计的
Blink、最基本的应用程序样品 Console Application
以至让开荒者自身挑选必要参与的来源档以至从预设设定起的 Empty。

下载Visual C++ for Linux Development extension或从Visual
Studio上的插件管理员来得到。近年来我们在Visual Studio上的Android
Tools上已有相依帮衬。借令你已经安装了VS的话,你可以借由Add Remove
Programs来新扩张那个功用,编辑VS然后在Visual C++移动设备支出下抉择他们。

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.

图片 9

Go to project properties and take a look under Build Events at Remote
Post-Build Events.

图片 10

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.

图片 11

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.

图片 12

你的首先个 VS Linux 项目

我们从创立一个主要调控台 app 带头。从沙盘模拟经营新扩展完你的类型后,在 printf
陈诉句的地点设下贰个中断点,然后敲击 F5 或远端 GDB
除错器开关。根据预设值,这些主要调控台 app 设定与 debug/x64
的意况相容。假诺您的远端连线标的是 x86 或 arm
结构,那你须要先更改上述设定。在自作者身教重于言教的那些模范我利用的是 x64 Ubuntu
VM。

图片 13

鉴于这是首先次对接到标的的 Linux
机器,所以会弹出三个接连资源信息视窗,是由在创立项目时所接触的。

图片 14

我们还要扶持密码以至表达格局的验证措施,包罗使用复杂密码的印证。在第三回中标连接后,大家会将您的过渡资源消息积累以便在未来亟需连接时急速存取。你可以从
Tools > Options > Cross Platform > Linux
的路子来保管你已囤积的接入资讯,以至科学,密码/复杂密码是已加密情势储存的。大家也同不常间布置在未来的换代版本中,在接连时不要求存放连结资源音讯。

在延续的历程中,你的来自档会被复制到远端的 Linux 机器上,并触发 gcc
并依照项指向性质设定来营造原始码。在项目建设结构完结之后,你的程序将会在远端的机器上实行,并终止在我们原先所设下的中断点上。

要起来二个新的项目方可通过以下渠道:Templates > Visual C++ > CrossPlatform > Linux。

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.

图片 15

Now, under Linker Input add the library dependencies: m;GL;GLU;glut.

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

图片 16

Now hit F5.

图片 17

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.

  图: 安装 Visual C++

Linux 项目性质

笔者们能够借由以下的品类性质来理解,东西是怎么被安插到远端 Linux
机器上的。

图片 18

在 remote settings 下,你能够看来 remote 根目录是预设在 ~/projects/
,且该路线下的远端项目目录会与大家的项目名称切合。从 Linux
机器上去看的话,我们得以在 ~/projects/ConsoleApplication1
下开采创设后的成品 main.cpp。

图片 19

依照项指标 General setting,能够驾驭到大家针对 Output 以致 Intermediate
路线是怎么设定的。除此而外,你能够窥见到这一个项目是被设定成贰个应用程序的
— 代表大家的花色实践档 ConsoleApplication1.out 是在 bin/x64/Debug/
路线下。其余能够小心到的是,我们也还要帮助静态甚至动态的设定格式。

脚下大家有多少个能够应用的模板:针对像Raspberry
Pi等物联网装置设计的Blink、最基本的应用程序样品Console
Application以至让开采者自身筛选要求参预的来源档以致从预设设定起的Empty。

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

  然后一旦再设置 Visual Studio GDB Debugger 这些增添套件,就能够在
Visual Studio 的 Visual C++ > 跨平台的花色项目中挑选 Makefile Project
(GDB卡塔尔 的档期的顺序范本。

相关文章