什么是相对路径,如&QUOT的好处; ../包括/ header.h"头球? [英] What are the benefits of a relative path such as "../include/header.h" for a header?

查看:174
本文介绍了什么是相对路径,如&QUOT的好处; ../包括/ header.h"头球?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我查看了问题如何使用include指令正确与< A HREF =htt​​p://stackoverflow.com/questions/179213/c-include-semantics> C ++的#include语义并没有解决这个 - 也不这么认为,当我输入标题的其他..

I've reviewed questions How to use include directive correctly and C++ #include semantics and neither addresses this - nor do the others suggested by SO when I typed the title...

什么,如果有的话,是写作的好处:

What, if any, are the benefits of writing:

#include "../include/someheader.h"
#include "../otherdir/another.h"

使用只是一个普通的文件名进行比较:

compared with using just a plain file name:

#include "someheader.h"
#include "another.h"

或许没有一个相对名称的 ..

#include "include/someheader.h"
#include "otherdir/another.h"

我看到的问题是:

The problems I see are:


  • 您不能移动的标题,而不用担心它的源文件包括它。

  • 您可以在依赖及错误报告标题很长的路径结束。我有一个今天以 ../ DIR1 /包括/../../包括/../ DIR2 /../包括/ header.h

我能看到的唯一好处是,虽然你并不需要移动文件,你也许可以逃脱不使用总是 -I '指令来找头,但是弹性的损失,且在分次目录编译的复杂性等似乎超过了益处。

The only merit I can see is that while you do not need to move files around, you might be able to get away without always using '-I' directives to find headers, but the loss of flexibility, and the complexity of compiling in sub-sub-directories, etc seems to outweigh the benefit.

所以,我俯瞰好处?


感谢您的输入。我认为共识是,有没有使用我俯瞰符号。任何重大利益。总体而言,我喜欢的地方/ header.h符号;我在做新的项目中使用它。一个我的工作是什么,但新的。

Thanks for the inputs. I think the consensus is that there aren't any major benefits to the notation using ".." that I'm overlooking. In general terms, I like the "somewhere/header.h" notation; I do use it in new projects. The one I'm working on is anything but new.

问题之一是,有各种套头的,经常用preFIX如 rspqr.h rsabc。 ^ h rsdef.h rsxyz.h 。这些都与在 rsmp 目录code,但某些标题是 rsmp 及其他在中央包括目录,它没有在它的子目录,如 rsmp 。 (再次为code的各种其他领域;有头在多个地点,由code等位随机必要的。)移动的东西左右是一个重要的问题,因为code已经变得如此卷积多年来。而makefile文件并不一致,其中设置 -I 选项。总而言之,这是不那么善意的忽视在一段十年的一个悲伤的故事。修复这一切没有打破任何东西将是一个长期的,乏味的工作。

One of the problems is that there are various sets of headers, often with a prefix such as rspqr.h, rsabc.h, rsdef.h, rsxyz.h. These are all related to code in the rsmp directory, but some of the headers are in rsmp and others are in the central include directory, which does not have sub-directories such as rsmp in it. (And repeat for the various other areas of the code; there are headers in multiple locations, needed randomly by other bits of code.) Moving stuff around is a major problem because the code has gotten so convoluted over the years. And the makefiles are not consistent in which -I options are provided. All in all, it is a sad story of not-so-benign neglect over a period of decades. Fixing it all without breaking anything is going to be a long, tedious job.

推荐答案

我preFER,因为它非常清楚的路径语法什么的命名空间或模块的头文件属于。

I prefer the path syntax as it makes it very clear what namespace or module the header file belongs to.

#include "Physics/Solver.h"

是很自我描述的,而不需要每个模块为preFIX他们的名字的头文件。

Is very self-describing without requiring every module to prefix their name to header files.

我几乎从来不使用..虽然语法,而是我有我的项目包括指定正确的基地位置。

I almost never use the ".." syntax though, instead I have my project includes specify the correct base locations.

这篇关于什么是相对路径,如&QUOT的好处; ../包括/ header.h&QUOT;头球?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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