让 Eclipse CDT 在生成的 Makefile 中使用相对包含路径

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3997152/
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 15:13:41  来源:igfitidea点击:

Getting Eclipse CDT to use relative include paths in generated Makefiles

eclipsemakefileeclipse-cdt

提问by Nikratio

I am using the Eclipse CDT. I have configured the "external Builder" and I am generating the Makefiles automatically. Unfortunately, the generated Makefiles contain the absolute include path. I would like to use the generated Makefiles on other systems (where Eclipse is not installed) - is there a way to make Eclipse use relative paths into the Makefile?

我正在使用 Eclipse CDT。我已经配置了“外部构建器”并且我正在自动生成 Makefile。不幸的是,生成的 Makefile 包含绝对包含路径。我想在其他系统(未安装 Eclipse)上使用生成的 Makefile - 有没有办法让 Eclipse 使用 Makefile 的相对路径?

I have configured my projects include directory under Settings -> Tool Settings -> GCC C Compiler -> Include Paths using ${workspace_log}.

我已经在 Settings -> Tool Settings -> GCC C Compiler -> Include Paths using ${workspace_log} 下配置了我的项目包含目录。

采纳答案by Itamar Katz

If you use relative path in the 'include paths' (instead of ${workspace_loc}), then the makefile (and .mk files it uses) will include relative paths as well.

如果您在“包含路径”(而不是${workspace_loc})中使用相对路径,那么生成文件(以及它使用的 .mk 文件)也将包含相对路径。

回答by Itamar Katz

There is a better way to do this: "Project > Properties > C/C++ Build > Settings > Tool Settings > Cross G++ [or GCC] Compiler > Includes". Click plus button, then write:

有一个更好的方法来做到这一点:“项目 > 属性 > C/C++ 构建 > 设置 > 工具设置 > 跨 G++ [或 GCC] 编译器 > 包含”。点击加号按钮,然后写:

"${ProjDirPath}/../../../somefolder1/somefolder2"

“${ProjDirPath}/../../../somefolder1/somefolder2”

This approach allows you to specify any external folder by relative path to your project folder, even if it is located in parent subfolders.

这种方法允许您通过项目文件夹的相对路径指定任何外部文件夹,即使它位于父子文件夹中。

回答by user3200000

The relative paths you add in "Project > Properties > C/C++ General > Paths and Symbols > Includes" tab are relative to your project folder.

您在“项目 > 属性 > C/C++ 常规 > 路径和符号 > 包含”选项卡中添加的相对路径与您的项目文件夹相关。

The ones that appear in the generated makefiles are relative to the main Makefile location.

出现在生成的 makefile 中的那些是相对于主 Makefile 位置的。

回答by JCQian

I found this question asked long time ago. I'm trying to setup GitLab CI with Eclipse CDT, the easiest way suggested is to use the existing makefile the CDT generated. But, I was unable to easily config the Eclipse CDT to generate the makefile in my project with relative path easily, I can see I can get "include" settings changed, but there are other files referenced in the makefile using absolute path in the make files too. So I just used a PowerShell script to update all the absolute path into relative path. Check the PWD for the absolute path, then count the ../ to back out to the root of the project. Mine was 5 folder deep.

我发现这个问题很久以前就被问到了。我正在尝试使用 Eclipse CDT 设置 GitLab CI,建议的最简单方法是使用 CDT 生成的现有 makefile。但是,我无法轻松地配置 Eclipse CDT 以轻松地使用相对路径在我的项目中生成生成文件,我可以看到我可以更改“包含”设置,但是在生成文件中使用绝对路径引用了其他文件。文件也是。所以我只是使用一个PowerShell脚本将所有绝对路径更新为相对路径。检查绝对路径的 PWD,然后计算 ../ 以返回到项目的根目录。我的是 5 个文件夹深。

ls *.mk -rec | %{ $f=$_; (gc $f.PSPath) | %{ $_ -replace "c:/absolute path", "../../../../.." } | sc $f.PSPath }