I installed the auto-complete-c-headers package and did the .emacs configs as follows:

; start auto-complete with emacs
(require 'auto-complete)
; do default config for auto-complete
(require 'auto-complete-config)
; let's define a function which initializes auto-complete-c-headers and gets called for c/c++ hooks
(defun my:ac-c-header-init ()
(require 'auto-complete-c-headers)
  (add-to-list 'ac-sources 'ac-source-c-headers)
  (add-to-list 'achead:include-directories '"/usr/include/c++/4.8
; now let's call this funcion from c/c++ hooks
(add-hook 'c++-mode-hook 'my:ac-c-header-init)
(add-hook 'c-mode-hook 'my:ac-c-header-init)

I included the directories listed by the command gcc -xc++ -E -v -.

The autocomplete works fine with C header files, but does nothing with the C++ ones.


It looks like you are incorrectly adding the c++ headers to achead:include-directories. Each header should be a separate item in the list, not the Heredoc-like syntax you're using. You are prepending just one string with embedded newlines, which of course does not exist on disk. Instead of:

(require 'auto-complete-c-headers) (add-to-list 'ac-sources 'ac-source-c-headers) (add-to-list 'achead:include-directories '"/usr/include/c++/4.8 /usr/include/x86_64-linux-gnu/c++/4.8 /usr/include/c++/4.8/backward /usr/lib/gcc/x86_64-linux-gnu/4.8/include /usr/local/include /usr/lib/gcc/x86_64-linux-gnu/4.8/include-fixed /usr/include/x86_64-linux-gnu /usr/include "))

Try this:

(require 'auto-complete-c-headers) (add-to-list 'ac-sources 'ac-source-c-headers) (setq achead:include-directories (append '("/usr/include/c++/4.8" "/usr/include/x86_64-linux-gnu/c++/4.8" "/usr/include/c++/4.8/backward" "/usr/lib/gcc/x86_64-linux-gnu/4.8/include" "/usr/lib/gcc/x86_64-linux-gnu/4.8/include-fixed" "/usr/include/x86_64-linux-gnu") achead:include-directories)))

The c header files probably work because by default, the package adds "/usr/include" and "/usr/local/include" to achead:include-directories.

| improve this answer | |
  • What does M-: achead:include-directories show in a c-++-mode buffer? – InHarmsWay May 27 '16 at 12:47
  • ("/usr/include/c++/4.8" "/usr/include/x86_64-linux-gnu/c++/4.8" "/usr/include/c++/4.8/backward" "/usr/lib/gcc/x86_64-linux-gnu/4.8/include" "/usr/lib/gcc/x86_64-linux-gnu/4.8/include-fixed" "/usr/include/x86_64-linux-gnu" "/usr/include/c++/4.8" "/usr/include/x86_64-linux-gnu/c++/4.8" "/usr/include/c++/4.8/backward" "/usr/lib/gcc/x86_64-linux-gnu/4.8/include" "/usr/lib/gcc/x86_64-linux-gnu/4.8/include-fixed" "/usr/include/x86_64-linux-gnu" ...) – user12177 May 27 '16 at 13:04
  • Looks OK. What doesn't work? Pressing <tab> in a #include <x|> (where x is some character that is a prefix to a file name that exists in one of those directories, and | represents the cursor) completes only c headers? What does evaluating ac-sources in that buffer show? – InHarmsWay May 27 '16 at 13:38
  • Without reason the things started to work. I don't know what I did. That evaluate command may have solved the problem? – user12177 May 27 '16 at 14:53
  • The evaluate command should have had no effect. Perhaps you were debugging in an intermediate state wherein all changes to the setup code had not yet propagated to your testing environment. Happens to me sometimes when I forget to evaluate the latest elisp code. – InHarmsWay May 27 '16 at 18:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy