Linux Programmer Gospel writes Linux in C + + on Visual Studio

Source: Internet
Author: User
Tags gdb debugger

Now we are developing a new plug-in that allows developers to build a suite of Visual Studio ( VS ) that can run C + + programs on Linux. Developers can use this plugin to transfer C + + programs to Linux servers, PCs, and mobile devices, as well as to connect these machines to your VS . VS will automatically replicate one copy and construct your source file at the far end, and then run the application with the debugger. Our program also provides system support for special architectures, including ARM. The article below will continue to cover the use of our new Linux program.

Currently we only support the provision of construction services on the remote target Linux machine. We are not restricting specific Linux releases, but we still have some dependencies on the performance of some tools. It is important to note that we need openssh-server, g++, GDB, and Gdbserver. Install them using the suite management tools that you're accustomed to, such as Debian-type Linux:

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

installation

Download Visual C + + for Linux development extension or from a plugin administrator on visual Studio . We currently have dependency support on Android Tools on Visual Studio . If you have installed VS, you can add these features by adding Remove Programs, edit vs and then select them under Visual C + + mobile device development.

To start a new project you can go through the following paths:Templates > Visual C + + > Cross Platform > Linux.


We currently have three templates available: Blink for IoT devices such as Raspberry Pi, the most basic application template Console application, and the ability for developers to choose the source file they want to add and the Empty from the preset.

your first VS Linux project

Let's start with building a console app. After adding your project from the template, set a breakpoint in the printf narrative and tap the F5 or remote GDB debugger button. Depending on the preset value, this console app is set to be compatible with the DEBUG/X64 environment. If your remote connection is labeled x86 or ARM architecture, you need to change the above settings first. In the example I demonstrated, I used the x64 Ubuntu VM.


Since this is the first time the Linux machine is connected to the underlying, a connection information window will pop up, triggered by the construction of the project.


We support both password and authentication forms, including authentication using complex passwords. After the first successful connection, we will store your link information for quick access when you need to connect in the future. You can manage your stored link information from Tools > Options > Cross Platform > Linux paths, and yes, passwords/complex passwords are stored in encrypted form. We also plan to store the link information in a future updated version without the need for a connection.

During the connection process, your source files are copied to the remote Linux machine, and GCC is triggered to construct the original code based on the project's property settings. After the project is constructed, your program will execute on the remote machine and stop at the point where we previously set up the breakpoint.


Linux Project Properties

We can use the following project properties to understand how things are deployed on a remote Linux machine.


Under Remote settings, you can see that the remote root directory is preset in ~/projects/, and the remote project directory under that path will match our project name. From the Linux machine to see, we can find the construction of the finished main.cpp under the ~/projects/consoleapplication1.


Based on the general setting of the project, you can see how we set the Output and intermediate path. In addition, you can find that this project is set up as an application-representing our project execution file Consoleapplication1.out is under the bin/x64/debug/path. It is also important to note that we support both static and dynamic formatting.

Linux Internet of Things Project

Now let's look at the parts of the IoT device-taking Raspberry Pi for example. You can use any type of Pi to perform Raspbian. In our Blink example we use wiringpi-if you do not have this installation option you can also choose to install from apt or source files. Add a link to the Tools > Options Search for Linux and click "Add" to add a link to your Raspberry Pi.


View the Remote post-build events under Build events from where the project properties are set.


You can use this setting to execute instructions on the Linux target where the project has been constructed remotely. This template has pre-programmed a GPIO pin for the LED output, so we do not need to execute our execution file as root.

Now connect an LED to the pin 17 position on the Raspberry Pi, such as:


Open the Main.cpp file and set the break point in place of the first digitalwrite delay call, then tap F5. You can see that your LED is on, and the execution program will stop at the point where you dropped it. Keep your program up to the next Digitalwrite call and you'll see the LED lights go out.

You can track all of the features we currently release for this system by browsing our IoT development page.

Desktop Applications

We have just introduced the non-interface (headless) and device-based Linux applications in the above article, what about desktop? Here we'll cover something special: We're going to execute an OpenGL application on the Linux desktop. The first thing to make sure is that your Linux desktop is set to include OpenGL, and the following are the apt packages we'll need: Libgles1-mesa, Libgles1-mesa-dev, FREEGLUT3, and Freeglut3-dev.

Next, create an empty Linux project, then go to Julien Guertault's OpenGL tutorial to download the source file for the spin box, unzip it and add the MAIN.C to your project. To be able to run Intellisense, you need to add OpenGL headers (headers) to VC + + directories and you can download them from OpenGL Registry. Now go to your project property settings and add the export display=:0.0 to the pre-launch command.


Then, add "M;gl" under Linker Input; Glu;glut "to the Library Dependencies field.

Also, verify that your remote settings are corresponding to the right machine.


Then press the F5.


There are some interesting places to go, like around 80 rows or so, where you can adjust the rotation of the block (try adjusting to the alpha value), or you can check the value entered when you press the keyboard in Keyboardfunc.

start your native Linux app development Journey

We expect you to have the same expectations as we have for these new and open possibilities.

Install Visual C + + for Linux development extension, try to see and tell us which ones you can run successfully, and which are the obstacles or problems you encounter. If you are interested in the area of the Internet of things, you can go to our IoT development page to get the latest news. You can contact us by using this blog, or by additional paging on the exhibition page, VS feedback channel, and @visualc on Twitter, @robotdad or my account.

This document is translated from: Visual C + + for Linux development

Linux Programmer Gospel writes Linux in C + + on Visual Studio

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.