vs2017 build linux c ++ development environment

Development environment

window 10 operating system, vs 2017 community edition, VMware12.5.7

Installation ubuntu14 desktop in VMware

vs 2017 installation

Download the official website address https://visualstudio.microsoft.com/zh-hans/?rr=https%3A%2F%2Fwww.microsoft.com%2Fzh-cn%2F

From the official website to download the latest vs 2017, need to pay attention to the installation process, if you need to linux c ++ build environment, you need to check the "use of linux c ++ development" tool set, see below

Configuration ubuntu environment

Installed ubuntu in good c ++ environment, because vs 2017 need to login to ubuntu system via ssh, ssh so also need to install the service, the command is as follows:

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

Start ssh service:

sudo service ssh start

vs2017 created linux project

Open vs2017, the following steps, File -> New Project -> Cross-platform -> linux-> console application (linux)

After the completion of the new project, vs2017 automatically generates a simple file maic.cpp

Menu bar, select Debug -> cross platform-> add the Ubuntu server the user input information into just created

Right solution, you can see the properties page of the current program, click the Configuration Properties -> General -> remote computer generated, just select the new account, you can see in this page, the default remote generated in the root directory "~ / projects "below, can be seen a little later in the corresponding directory ubuntu project generates code.

Menu bar, select Debug -> Linux Console Open the Console program linux

Can break point in the program, click on the button to run the debugger, you can see the console print out the information

Landing ubuntu, in projects under ~ / directory can see the newly generated project folder "test"

Encounter problems

上述是一个简单的开发演示,在实际的工作中,代码可能很复杂。因为这几天在学习linux的IO多路复用机制,从网上找了一个稍微复杂的通信程序,代码来自于博客https://www.cnblogs.com/Anker/p/3261006.html,源代码有一处错误,需加上#include <arpa/inet.h>。这个程序的功能是客户端向服务器发送信息,服务器接收输出并原样发送回给客户端,客户端接收到输出到终端。其中使用一些linux中的库文件。

问题1 无法找到库文件

在博客https://www.cnblogs.com/xylc/p/6533716.html?&from=androidqq 看到一个解决方法,将ubuntu下面/usr/include、/usr/local/include等目录复制到vs的linux header path(在我的机器中,地址为C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\IDE\VC\Linux\include\usr)。

问题2 gdbserver模式无法使用

vs2017进行调试有两种方式,gdb和gdb-server,可以在菜单栏 调试->配置属性->调试->调试模式中进行配置,关于这两种模式的不同,官方文档的解释如下:

  • 在“gdbserver”模式中,GDB 在本地运行,连接到在远程系统上运行的 gdbserver。 请注意,这是 Linux 控制台窗口唯一支持的模式。
  • 在“gdb”模式中,Visual Studio 调试器驱动远程系统上的 GDB,如果 GDB 的本地版本与目标计算机上安装的版本不兼容,则远程系统上的 GDB 更易兼容。 |

从网上找了很多的资料,重新更新了ubuntu中的gdbserver,结果还是不行,因为我之前使用的是ubuntu17的server版本,无奈使用ubuntu14的桌面版,问题立马得到解决,目前仍然不知道gdbserver模型为什么无法使用,如果有路过的大神看到,希望评论区可以留言。

问题3 错误Stopped (tty input)

在运行gdb模式下运 行客户端的时候,客户端从控制台接受数据的那一段代码报Stopped (tty input)错误,通过看官方文档发现gdb模式不支持控制台交互,改成gdbserver模式后能正常使用。

最终运行结果

最终成功运行服务端和客户端程序,先启动服务端,再运行客户端,下图中分别为服务端和客户端运行情况。当客户端再控制台输入信息,服务端能接收,并回传给客户端在控制台显示。

Guess you like

Origin www.cnblogs.com/YZFHKMS-X/p/11763499.html