使用Visual C ++进行Linux开发时是否可以直接使用linux文件夹/usr/include [英] Is it possible to use directly the linux folder /usr/include when use Visual C++ for Linux Development

查看:130
本文介绍了使用Visual C ++进行Linux开发时是否可以直接使用linux文件夹/usr/include的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试使用针对ubuntu 16.04 VM的Visual C ++ for Linux Development插件.与VM的连接以及本地文件到远程文件夹/home/user/projects/projectx的传输均成功.但是,当我尝试将usr/include或usr/local/include文件夹添加到其他包含目录时,无法解析相关的标头.我试图使用路径 $(RemoteRootDir)/../../../usr/local/include.我还尝试在项目文件夹内创建usr/include和usr/local/include文件夹的符号链接,并提供相关路径,但是同样无法解析标头.这种直接分配是可能的,还是仅应使用所需linux文件夹的本地副本?

I trying to use the Visual C++ for Linux Development plugin targeting an ubuntu 16.04 VM. The connection with VM and the transfer of the local files to remote folder /home/user/projects/projectx were successful. However when I tried to add the usr/include or the usr/local/include folder to the additional include directories the relevant headers could not be resolved. I tried to use the path $(RemoteRootDir)/../../../usr/local/include. I also tried to create symlinks of the usr/include and usr/local/include folders inside the projects folder and giving the relevant path but again the headers could not be resolved. Is this direct assignment possible or one should only use local copies of the needed linux folders?

推荐答案

要考虑两种类型的包含文件查找.首先,在Visual Studio IDE中工作时,IntelliSense将查找标题和定义主题,以帮助编辑.在这种情况下,文件必须位于Windows主机可访问的路径上. VCLinux从Windwos主机上的/usr/include安装大多数头文件的通用副本.在VS2015中,可以在C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\Linux\include\usr\include\x86_64-linux-gnu\中找到它们,而在VS2017中,它们可以在C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\IDE\VC\Linux\include\usr\include中找到(适当时将Community更改为Professional或Enterprise).这会自动包含在Visual Studio的预定义包含路径中.

There are two types of include file lookup to consider. First, when working in the Visual Studio IDE, IntelliSense will look up the headers, and definitions therin, to assist editing. In this case the files need to be on a path accessible by the Windows host. VCLinux installs generic copies of most of the header files from /usr/include on the Windwos host. In VS2015 they can be found in C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\Linux\include\usr\include\x86_64-linux-gnu\ and in VS2017 they are in C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\IDE\VC\Linux\include\usr\include (change Community to Professional or Enterprise as appropriate). This is automatically included in the predefined include path for Visual Studio.

第二,GCC(g ++)必须能够在Linux远程平台上的编译过程中找到标头.在这种情况下,文件必须位于Linux系统可访问的pth位置.不需要添加/usr/include等,因为默认情况下,GCC会在此处查找.您可以通过以下方式发现默认的包含路径

Second, GCC (g++) needs to be able to find the headers during compilation on the Linux remote. In this case the files must be on a pth accessible by the Linux system. There is no need to add /usr/include etc. because GCC looks there by default. You can discover the default include path with

g++ -v -x c -E -

在任何情况下,都没有任何理由将/usr/include添加到项目中的include路径.如果IntelliSense找不到应该在/usr/include中的标头,则可能会丢失该标头. 如此处

In neither case is there any reason to add /usr/include to the include path in your project. If IntelliSense can't find a header that should be in /usr/include then it might be missing. As here.

通常,您可以将Linux系统上的任何路径添加到包含路径. GCC将找到它,并且头文件therin和您的程序将进行编译(所有其他条件相同).但是,Visual Studio(IntelliSense)如果看不到相同的标题,则可能会标记错误.包含路径可以是绝对路径,也可以是相对路径,尽管在Linux端要注意相对路径,因为参考点是远程根目录而不是项目目录.

On a more general point, you can add any path on the Linux system to the include path. GCC will find it and the headers therin and your program will compile (all other things being equal). But Visual Studio (IntelliSense) might flag an error if it can't see the same headers. Include paths can be absolute or relative although care should be take with relative paths on the Linux side because the reference point is the remote root not the project directory.

VCLinux(1.0.6)要求两次指定包含路径,一次是在Windows端,一次是在Linux端.这可能会导致两个系统上具有相同路径(通常是相对路径)的文件夹被复制.

VCLinux (1.0.6) requires that include paths are specified twice, once for the Windows side and again for the Linux side. This might result in a folder that has the same path (typically relative) on both systems being duplicated.

这篇关于使用Visual C ++进行Linux开发时是否可以直接使用linux文件夹/usr/include的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆