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-13 12:49:19

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

visual studio 开发linux程序

VisualGDB支持Linux的原理是,通过ssh连接到Linux系统上通过ssh给linux下达命令 . (类似visualgdb的有windgb  ,这2个都是商业软件.) Visual GDB把GDB调试工具集成到visual studio 开发环境中,在调试过程中,可以使用visual studio原有的单步执行.设定断定等快捷键,还可以在visual GDB session的窗口中输入GDB的调试命令,集成了visualGDB之后还可以在程序执行的过程中用鼠标悬停的方式查看和修改变量

用Visual Studio编辑Linux代码

估计很多人都是用惯了Visual Studio的主,怎么也不适应Linux的一套编辑器,比如vim.source insight这些东西,可视化的eclipse效果还好点,但一般以远程共享一台Linux服务器为主,没那么好条件一人一个Linux机器. 我用了有几个月的insight,也就看看代码,反正个人感觉就是别扭,现在换成用VS编辑代码,感觉爽多了. 大致方法如下: (1)从svn下载Linux代码到本地目录. (2)打开Visual studio,选择“File” -> “New” ->

使用Visual VM 查看linux中tomcat运行时JVM内存

前言:在生产环境中经常发生服务器内存溢出,假死或者线程死锁等异常,导致服务不可用.我们经常使用的解决方法是通过分析错误日记,然后去寻找代码到底哪里出现了问题,这样的方式也许会奏效,但是排查起来耗费时间比较多,或者说本身代码本身就没有错,而是访问量大时候消耗内存太多,垃圾对象没有及时回收等等其他情况导致的,这样排查异常起来异常困难,那么有没有一些可视化的工具,帮助我们可以详细地查看当前应用服务的内存情况,从而为我们在解决异常.优化代码.优化服务等方面提供一些建议呢?幸好,jdk为我们免费提供一个这

解决Visual C++ for Linux: -L"~/projects/path_to_lib_folder" 无法设置library search path的问题

最近倒腾Linux C/C++项目.以目前的情况来说,要生成编译(build)一个Linux工程脚本,首选的工具必定是CMake.这也是我之前Linux项目的首选.不过自从VS IDE支持Linux C/C++开发后,也尝试这通过一些小demo来体验MS的解决方案.总得来说还可以,但是有个大问题因为一直没时间搞,就没有深入. 这里通过一个假定的场景来说这个问题. 在VS Linux项目里,如果一个解决方案下面有多个工程,比方说有两个工程A(.out)和B(.so),当工程A依赖工程B时我们需要设

2.6 visual studio开发linux程序

2.6.1 前言   在linux环境下开发C++程序,除了需要掌握C++的知识外,还需要掌握如何写makefile和使用GDB进行调试,这对于不熟悉makefile和GDB的开发人员是比较麻烦的,目前vs2015及以上的版本能够支持linux c++程序的开发和调试,与传统vs上的windows编程不同的是,vs所需要的Linux环境需要搭载在一个linux的服务器上,vs相当于将windows系统和这个linux系统之间建立了某种映射,可以将代码复制到linux中对应的目录中,并且windo

Visual Studio add linux Project

//https://blog.csdn.net/lanxiaziyi/article/details/81508499 { 使用vs2017进行linux下的开发现在 加点注意事项:1,依赖的库,都要在vs的配置文件中置指定好.例如:-levent -lpthread -L/root/freeswitch/libs/esl/.libs 1在 属性页->配置属性->链接器->命令行->其他选项 中添加.还可以在 属性页->配置属性->链接器->输入->库依赖项

【Linux程序员福音】在Visual Studio上用C++写Linux

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

使用vs2015开发linux:Ubuntu程序

官方介绍这个插件的博客:(https://blogs.msdn.microsoft.com/vcblog/2016/03/30/visual-c-for-linux-development/) 1.首先下载vs2015 with update3 2.然后下载Visual C++ for Linux Development,即 "VC_Linux.exe" (https://visualstudiogallery.msdn.microsoft.com/725025cf-7067-45c2

VS2015配置Linux开发远程调试

# VS2015配置Linux开发远程调试 ### 简介-----------------------------vs2015支持跨平台开发 ### 软件环境------------------------------ VS2015 update3- Visual C++ for Linux Development(VC_Linux.exe) ### 安装步骤------------------------------ 安装VS2015 update3版本(直接按照后就是VS2015,不是补丁)