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

低调大师中文资讯倾力打造互联网数据资讯、行业资源、电子商务、移动互联网、网络营销平台。
持续更新报道IT业界、互联网、市场资讯、驱动更新,是最及时权威的产业资讯及硬件资讯报道平台。
转载内容版权归作者及来源网站所有,本站原创内容转载请注明来源。
-
上一篇
AWS Submit 2016 观感
版权声明:本文为半吊子子全栈工匠(wireless_com,同公众号)原创文章,未经允许不得转载。 https://blog.csdn.net/wireless_com/article/details/52493465 9月7日,AWS Submit 2016的第一天,人潮涌动,据说这是一个万人大会。 由于在一层看了一会参展商,9点多上楼的时候,告知主会场已满,居然只能在楼下看实况转播了。因此,先看一下参展商的走向。 混合云 随着业界对“传统IT向云转型“的认可,混合云的时代终于来了。混合云如何实现敏捷性呢? 基于云的持续交付么? 采用云原生应用架构么? …… 混合云显得有些不够用了,开始使用“超融合“一词了。以应用为中心,策略驱动的可扩展,发布的自动化,自服务商店,企业可扩展,混合云的各个层面都开始具体化了。 基础设施 基础设施和AWS有什么关系?由于政策原因,落地需要本地的基础设施,据说AWS 在宁夏的IDC 很快就交付使用了。 另外在,混合云中的专线服务, direct connect 之类还是很有市场的。 运维管理 DevOps 知易行难,在大系统运维监控中,zabbix 还是...
-
下一篇
不再做“异教徒”——揭开数据库PostgreSQL的神秘面纱
中国云计算产业最具影响力的盛会之一——2016杭州云栖大会(https://yunqi.aliyun.com/)将在云栖小镇召开。连续举办七届的云栖大会一直是业界了解阿里云计算生态发展和应用趋势、体验前沿技术和产品的最佳平台,来自海内外的上万名开发者、创业者聚集于此,分享着他们对云计算的思考与实践经验。7年来,从产品发布到行业解决方案展示,从关注技术到技术与服务并重,从单一的客户到生态全景的展现,大会的核心内容一直在“进化”,而2016年杭州云栖大会,则以“飞天・进化”为主题。飞天是整个阿里云的核心技术部分,是阿里云产品服务的基石,从2009年写下飞天第一行代码,到成为阿里巴巴所有核心业务数据处理的平台,从为国内中小创新企业、政府机构提供计算和数据处理能力,到触角加速延伸覆盖服务于全球200多个国家和地区……历经7载,飞天已进化成为世界级计算服务平台。本次大会,内容规模将比去年翻倍,从原本2天的议程增加至4天,从10月13日持续到16日,届时将有超过400场主题演讲、数万平米创新展览体验区和国内外顶尖科技亮相,而阿里巴巴集团董事局主席马云也将参加大会并发言。 为了让大家更为深入地了解...
相关文章
文章评论
共有0条评论来说两句吧...