4

I've recently started using irony-mode for completion in emacs (24.3.1). However, I seem unable to add additional system include paths to package.

I have this code in my config:

(defun ac-cc-mode-clang-hooks ()
  (yas/minor-mode-on)
  (auto-complete-mode 1)

  ;; avoid enabling irony-mode in modes that inherits c-mode, e.g: php-mode
  (when (member major-mode irony-known-modes)
       (irony-mode 1))

  ;; set compiler flags to include header files
  (setq irony-compile-flags '("-Iinc"))
  (irony-reload-flags))

(add-hook 'c++-mode-hook 'ac-cc-mode-clang-hooks)
(add-hook 'c-mode-hook 'ac-cc-mode-clang-hooks)

irony-mode is loaded correctly and completion works perfectly for include paths which the compiler knows explicitly (i.e. everything printed by echo "" | g++ -v -x c++ -E -) but the additional include path inc is not picked up (does not matter whether its a relative or absolute path).

However, if I add the information to the .clang_complete file and load it using C-c C-b the include path is recognised and used. Obviously this is a less than ideal setup because

  1. I don't want to create a .clang_complete file for each single piece of code I'm working on
  2. The .clang_complete file is not loaded automatically.

Is there some working method (which does not involve a per-project setup, I don't want to create project management files for each piece of code) for telling irony-mode where to look for header files?

elemakil
  • 3,681
  • 28
  • 53

1 Answers1

4

You can take a look here: https://github.com/Sarcasm/irony-mode#i-got-an-error-due-to-stdargh-how-to-solve-this

The variable irony-libclang-additional-flags should meet your needs. It should work without calling irony-reload-flags.

It's not a buffer-local variable though, so you don't need to put it in the hook.

I would recommend the following:

(setq irony-libclang-additional-flags
      (append '("-I" "inc") irony-libclang-additional-flags))
Guillaume Papin
  • 1,370
  • 11
  • 16
  • This works perfectly for a global (absolute) path. Two more questions: 1) How do I add multiple paths? Do I use `'("-I" "/IncOne" "-I" "/IncTwo")`, and 2) I think this is not working with relative paths because using your above code does not pick up a header file in the subdirectory `inc`. The logfile says: `1 errors/warnings found during completion. /tmp/!home!elemakil!Temp!FooBar.cpp:2:10: fatal error: 'SomeInc.h' file not found` so I guess that the problem is that copying the source to `/tmp` invalidates relative includes. Can this be fixed? – elemakil Dec 04 '13 at 15:49
  • 1) Yes. 2) You are right, it's fixed now, thank you for your input. 3) Do not hesitate to make an issue on Github, I stumbled upon this issue by chance. – Guillaume Papin Dec 05 '13 at 00:43
  • Works like a charm now! – elemakil Dec 05 '13 at 10:00
  • Neither the link you pointed out, nor the variable you mentioned is present at the present moment. I found a variable «irony-additional-clang-options», but for some reason the description admonishes to not use it for a header additional paths. What to use then is unclear. – Hi-Angel Jan 09 '15 at 07:12
  • 1
    I will update my answers but please create an issue on Github for this or post on http://emacs.stackexchange.com/. For now there is no proper way to set the default options, you can use `irony-additional-clang-options` in the meantime but a better alternative will be available in the future. – Guillaume Papin Jan 09 '15 at 09:12