Sarcasm / irony-mode

A C/C++ minor mode for Emacs powered by libclang
GNU General Public License v3.0
907 stars 99 forks source link

Compilation database behaves strangely in headers with out-of-source compile_commands.json #193

Open russellmcc opened 9 years ago

russellmcc commented 9 years ago

I'm using ninja for a project, and I'm trying to get flycheck-irony working. It's looking really good so far, except for some strange problems with header files.

Here's my project layout:

This is the preferred layout for the ninja build tool. I generated compile_commands.json using ninja.

Since the compile_commands.json is in a separate build directory and not directly in the source directory or a parent, irony-cdb doesn't find it automatically. To add it, I used irony-cdb-json-add-compile-commands-path, I set the project root to "root", and the compile_commands.json appropriately.

It seems like the cdb-json-projects file is correct:

cat ~/.emacs.d/irony/cdb-json-projects 
;; -*- emacs-lisp -*-
;;
;; JSON Compilation Database project list.
;;
;; File auto-generated by irony-cdb-json.
;;
(("<root>" . "<root>/out/Default/compile_commands.json"))

I ran the check-compile-options function that you provided here, output from the header file was:

I: found compilation database: <root>/out/Default/compile_commands.json
I: found by guessing: (((-MMD -MF obj/src/CoreAudioSDK/foo.CAStreamBasicDescription.o.d -I../../src -I../../src/CoreAudioSDK -fasm-blocks -mpascal-strings -Os -gdwarf-2 -arch x86_64 -std=c++14) . <root>/out/Default))

However, I'm getting some errors from flycheck that indicate it doesn't understand the -std=c++14 option:

    6  10 error           'type_traits' file not found... (irony)
   10  33 error           no type named 'function' in namespace 'std'... (irony)
   16  10 error           no type named 'unique_ptr' in namespace 'std'... (irony)

The corresponding .cpp file seems totally fine.

One thing that does work is copying the compile_commands.json into <root>, clearing my cdb-json-projects, and then modifying the compile_commands.json file by hand to have a working directory corresponding to <root>.

In addition to the flycheck problems, auto complete seems to not understand that we're in std=c++14 either.

Sarcasm commented 9 years ago

What Emacs version do you have?

What does irony-cdb-menu tells you?

Is <root> "a full/absolute path" or something abbreviated (e.g: ~/)?

russellmcc commented 9 years ago

I have 24.4 from https://github.com/caskroom/homebrew-cask for mac.

irony-cdb-menu shows

Compilation Database: irony-cdb-json

  Working Directory: <root>/out/Default
  Compile Options:   -MMD -MF obj/src/CoreAudioSDK/foo.CAStreamBasicDescription.o.d -I../../src -I../../src/CoreAudioSDK -fasm-blocks -mpascal-strings -Os -gdwarf-2 -arch x86_64 -std=c++14

[q] to quit

Yeah, <root> is a full path. I haven't seen an abbreviation anywhere.

Thanks for looking into this!