malinka icon indicating copy to clipboard operation
malinka copied to clipboard

Compilation command for header files

Open orki opened this issue 10 years ago • 4 comments

ede-compdb has a very interesting solution for compilation command for header files: if there exists an "other file" (found via projectile-find-other-file) which has a compilation command associated with it, then the same command is used with the other file name replaced by the header file name; if other file does not exist or does not have a compilation command, it finds a compilation command that shares the maximum length path with the header file and then uses it. Is it possible for this logic to become part of malinka?

orki avatar Nov 04 '15 04:11 orki

Hello @orki,

I am not sure I understand exactly what you mean. Why do you need a compilation command for header files? Headers are not compiled, only sources are.

Also where would you need a compilation command? Compilation commands are added to compile_commands.json and then fed to rtags, flycheck e.t.c.. You wouldn't need to look at them directly.

LefterisJP avatar Nov 05 '15 08:11 LefterisJP

On Thu 2015-11-05 12:55:06AM PST, Lefteris Karapetsas [email protected] wrote:

I am not sure I understand exactly what you mean. Why do you need a compilation command for header files? Headers are not compiled, only sources are.

That is correct, but without sending a "compile command" to rtags for a header file or a template implementation file, as far as I know, there is no way to obtain completion and other rtags goodies when editing header files. See the following in ede-compdb documentation for full description of how it handles the issue: https://github.com/randomphrase/ede-compdb#header-files

Also where would you need a compilation command? Compilation commands are added to compile_commands.json and then fed to rtags, flycheck e.t.c.. You wouldn't need to look at them directly.

That is correct as well. I don't need to look at it directly; I just need it to be passed to rtags and flycheck. As a C++ library writer focused mostly on generic code, I mostly work in non-compiled code (mostly header and template implementation files) and this is an important feature for me.

orki avatar Nov 06 '15 19:11 orki

I am not sure about that, I can properly jump around template files using rtags. If a source file includes a compile file it should be indexed by rtags. Maybe there is another reason why this does not work for you. Can you make a tiny project with a reproducible example? Tell me what the expected behavious is and what you actually get.

LefterisJP avatar Nov 07 '15 07:11 LefterisJP

This will work most of the time with rtags because rtags will find all the includes of the source files and then parse these files too, but that doesn't guarantee that other projects will do the same, irony, flycheck for example will not have the correct compiler flags and hence will not work correctly.

Actually neither rtags will have the correct compiler flags (but I don't think it matters in the rtags case), since the header file will be parsed with the source file that included it compiler flags.. which should for example have a include path for a library X which the header shouldn't have, in flycheck case, for example, this would make flycheck not show an error when using something of library X in the header (since it would be using the cpp file compiler flags which have support for X instead of it's own flags which doesn't have that support) even thought it should.

As a solution for this, I've made some changes to the cmake source code to export header compiler flags information to compilation_commands.json file, but I'm not sure it will be accepted mainstream, you can see the issue report in this link https://gitlab.kitware.com/cmake/cmake/issues/16285

sezaru avatar Sep 07 '16 14:09 sezaru