Eclipse CDT:如何通过相对路径引用 3rd 方包含

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1089490/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 13:52:05  来源:igfitidea点击:

Eclipse CDT: How to reference 3rd party includes via a Relative path

c++eclipseboosteclipse-cdt

提问by Alex Black

I'm new to Eclipse-CDT, setting up a new project for the first time. I'm trying to reference Boost withouthardcoding an absolute path.

我是 Eclipse-CDT 的新手,第一次建立一个新项目。我试图在硬编码绝对路径的情况下引用 Boost 。

I've put boost in my workspace folder, e.g. /home/user/workspace/boost_1_39_0

我已将 boost 放在我的工作区文件夹中,例如 /home/user/workspace/boost_1_39_0

I was then hoping to add an include directory pointing to that folder relative to the workspace, but Eclipse won't do that, it seems to only want to point to thinks in /home/user/workspace/[MyProjectNameHere]

然后我希望添加一个指向相对于工作区的文件夹的包含目录,但 Eclipse 不会这样做,它似乎只想指向 /home/user/workspace/[MyProjectNameHere]

Any tips? It doesn't seem to make sense to copy Boost into my project folder, because then it shows up in Eclipse and Eclipse wants to build it (sure, I couldexclude it).

有小费吗?将 Boost 复制到我的项目文件夹似乎没有意义,因为它会出现在 Eclipse 中并且 Eclipse 想要构建它(当然,我可以排除它)。

  • Alex
  • 亚历克斯

采纳答案by Michael Burr

When adding an include file path in the CDT project (Project Properties/C/C++ General/Paths and Symbols), there are 3 buttons to browse for a location:

在 CDT 项目(项目属性/C/C++ 常规/路径和符号)中添加包含文件路径时,有 3 个按钮可以浏览位置:

  • Variables...
  • Workspace...
  • File system...
  • 变量...
  • 工作区...
  • 文件系统...

If you press the Workspace... button, the path will be relative to the workspace/project. If you select the Variables... button, you'll get to incorporate variables such as ${WorkspaceDirPath}. The variables can also reference environment variables, which might be handy if you want a single install of boost to be referenced from projects that might reside anywhere on your machine.

如果您按下工作区...按钮,路径将相对于工作区/项目。如果您选择变量...按钮,您将可以合并诸如${WorkspaceDirPath}. 这些变量还可以引用环境变量,如果您希望从可能驻留在机器上任何位置的项目中引用单个 boost 安装,这可能会很方便。

If you incorporate variables into the path, make sure the "Is a workspace path" option is checked - otherwise the variable seems to get evaluated when you press "OK" instead of staying a variable to be evaluated at build time.

如果您将变量合并到路径中,请确保选中“是工作区路径”选项 - 否则当您按下“确定”时该变量似乎会被评估,而不是在构建时保留要评估的变量。

回答by Alex Black

I got this working doing roughly what Michael Burr suggested above:

我大致按照 Michael Burr 上面的建议进行了这项工作:

Under Project Properties/C/C++ General/Paths and Symbols, I added paths like this:

在 Project Properties/C/C++ General/Paths and Symbols 下,我添加了这样的路径:

${ProjDirPath}/../boost_1_39_0

${ProjDirPath}/../boost_1_39_0

  • Alex
  • 亚历克斯

回答by nathan

IIRC, you should be able to right click the project and go into the C/C++ general settings. From there you can add specific include directories for the project to reference. Here's a couple of links that may help...

IIRC,您应该可以右键单击该项目并进入 C/C++ 常规设置。从那里您可以添加特定的包含目录以供项目引用。这里有几个链接可能会有所帮助...

IBM Article

IBM 文章

Eclipse Development

日食开发

回答by wakjah

I am using Eclipse Luna and found the accepted answer to be no longer accurate. After a bit of head scratching, it seems that a couple of changes have happened in the past few years (at least, this is what happened on my system):

我正在使用 Eclipse Luna,发现接受的答案不再准确。经过一番挠头,似乎过去几年发生了一些变化(至少,这是在我的系统上发生的事情):

  • Eclipse no longer expands variables when you click "OK" if you have notticked "Is workspace path".
  • Eclipse cannot find any paths that are relative to the workspace unless they actually refer to projects in the workspace. Any paths that cannot be found by Eclipse will notbe added to the build command line with a -Ior other relevant switch
  • 如果您没有勾选“是工作区路径”,那么当您单击“确定”时,Eclipse 将不再展开变量。
  • Eclipse 无法找到任何相对于工作区的路径,除非它们实际上引用了工作区中的项目。不能由Eclipse中发现的任何路径将被添加到构建命令行用-I或其他相关的开关

For this to work, therefore, I had to enter ${ProjDirPath}/../whateveras a non workspace-relativepath, and the variable is not expanded until compile time.

对于这项工作,因此,我不得不进入${ProjDirPath}/../whatever一个非工作空间的相对路径,该变量才会展开编译时间。