I am starting to develop a ROS (Robot Operating System) application for the first time using Emacs. Here is my ~/.emacs.d/init.el
configuration for Flycheck and company packages:
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Flycheck
;;;;;;;; Description: code linting (particularly C/C++ for me)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(require 'cc-mode)
(add-hook 'c++-mode-hook 'flycheck-mode)
(add-hook 'c-mode-hook 'flycheck-mode)
;; Check buffer on save, new line and immediately after anbling flycheck-mode
(setq flycheck-check-syntax-automatically '(mode-enabled save)) ;; new-line also possible
;; Add include paths
(add-hook 'c++-mode-hook
(lambda () (setq flycheck-clang-include-path
(list (expand-file-name "/opt/ros/kinetic/include/")))))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; company-mode
;;;;;;;; Description: text completion framework
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(require 'company)
;; Use company-mode in all buffers
(add-hook 'after-init-hook 'global-company-mode)
;; Use company-mode with Clang
(setq company-backends (delete 'company-semantic company-backends))
(set 'company-clang-arguments (list "-std=c++11")) ;; enable C++11 code completion
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Irony
;;;;;;;; Description: asynchronous completion capability for company-mode
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(add-hook 'c++-mode-hook 'irony-mode)
(add-hook 'c-mode-hook 'irony-mode)
(add-hook 'objc-mode-hook 'irony-mode)
(defun my-irony-mode-hook ()
(define-key irony-mode-map [remap completion-at-point]
'irony-completion-at-point-async)
(define-key irony-mode-map [remap complete-symbol]
'irony-completion-at-point-async))
(add-hook 'irony-mode-hook 'my-irony-mode-hook)
(add-hook 'irony-mode-hook 'irony-cdb-autosetup-compile-options)
;; Use comapny-mode with Irony
(add-hook 'irony-mode-hook 'company-irony-setup-begin-commands)
(setq company-backends (delete 'company-semantic company-backends))
;; Enable tab-completion with no delay
(setq company-idle-delay 0)
(define-key c-mode-base-map (kbd "<S-SPC>") 'company-complete)
;; Add support for completing C/C++ headers
(require 'company-irony-c-headers)
(eval-after-load 'company
'(add-to-list
'company-backends '(company-irony-c-headers company-irony)))
;;(add-to-list 'company-c-headers-path-system "/usr/include/c++/5.4.0/")
;; Integrate Irony with Flycheck
(eval-after-load 'flycheck
'(add-hook 'flycheck-mode-hook #'flycheck-irony-setup))
;; Set cppcheck standard to C++11
(setq irony-additional-clang-options '("-std=c++11"))
My problem is that it seems like Flycheck is not recognizing where the ROS header files are located. On my system, they are all in /opt/ros/kinetic/include/
and I tried to include this path in the above code with the command:
;; Add include paths
(add-hook 'c++-mode-hook
(lambda () (setq flycheck-clang-include-path
(list (expand-file-name "/opt/ros/kinetic/include/")))))
However, this seems to not fix things. I still get the error:
Please help me with an answer on the best practice of adding custom include paths for projects for both Flycheck and company-mode to use, with the include path in this particular case being /opt/ros/kinetic/include
. Thank you!