Getting Eclipse CDT to use relative include paths in generated Makefiles
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?
I have configured开发者_开发知识库 my projects include directory under Settings -> Tool Settings -> GCC C Compiler -> Include Paths using ${workspace_log}.
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:
"${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.
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.
The relative paths you add in "Project > Properties > C/C++ General > Paths and Symbols > Includes" tab are relative to your project folder.
The ones that appear in the generated makefiles are relative to the main Makefile location.
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.
ls *.mk -rec | %{ $f=$_; (gc $f.PSPath) | %{ $_ -replace "c:/absolute path", "../../../../.." } | sc $f.PSPath }
精彩评论