VS2017 develops new projects for Linux programs

To develop linux programs using vs2017, you must first install the linux development components, which can be selected during installation, or installed using the online installation tool after the installation is complete. As shown in the figure below, select the penguin.



The new program is relatively simple, find Visual C++ > Cross-platform > Linux in File > New > Project, and select the corresponding project on the right.


The empty project is a blank project without a file. After it is created, you can add files by yourself.

The console project has one more main.cpp than the empty project, which is a simple code that can be compiled directly.

Blinking is an embedded project of a development board, it seems to be a development board of Inetl, the sample program can light up an LED

The makefile project is a project that depends on the linux toolset, mainly using the linux toolchain to compile programs


After creating a new project, the first compilation will allow you to log in to the remote linux server. After entering the IP, user name, and password, you can compile and debug linux programs just like compiling and debugging Windows programs.

By default, a project will create a project directory under the ~/projects path of the remote linux server, which is used to copy the source code, store intermediate files and target files, which can be modified in the project properties interface, as shown below


The above are the default options, you can modify them according to your needs. If you don't want to copy the source code on linux, you can click the copy source on the left, and change Yes to No in the copy source option on the copy source interface.

If the version of linux is old and the compiler does not support the latest language standard, you can modify it on the c++>language page on the left.

When installing VS2017, some linux header files will be installed, but not all of them. Some header files are not available. You need to copy the files in the /usr/include directory on the linux machine to the Windows machine, and add the copied directory to the project. directory of references. I am lazy, so I copied it directly to the default linux header file directory of VS2017, ie

C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Common7\IDE\VC\Linux\include\usr\include

If the program needs a terminal to run, you can find the debug>linux console in the system menu of VS to open a simulated terminal. This is a very simple terminal that can only display the input and output of the program. If you want to input the runtime to the debugger Parameters, please specify in the debugging, program parameter options of the property page, in addition, you can also specify the working directory of the linux program in the working directory option.


This article first briefly introduces so much, and the next article will take an unzip source code as an example to introduce how to compile an existing makefile project.

For more information, see Microsoft's official blog post https://blogs.msdn.microsoft.com/vcblog/2016/03/30/visual-c-for-linux-development/

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325384842&siteId=291194637