IDE Setup: Difference between revisions

From TUDOS-Wiki
Jump to navigationJump to search
BjoernD (talk | contribs)
BjoernD (talk | contribs)
Emacs completion setup for L4Re
 
(2 intermediate revisions by the same user not shown)
Line 28: Line 28:
  /home/doebel/src/tudos/src/build/include/contrib/lwip
  /home/doebel/src/tudos/src/build/include/contrib/lwip
  /home/doebel/src/tudos/src/build/include/contrib/zlib
  /home/doebel/src/tudos/src/build/include/contrib/zlib
== VIM / YouCompleteMe ==
VIM's excellent [https://github.com/Valloric/YouCompleteMe YouCompleteMe] plugin provides C/C++ completion and works for L4Re with some tweaks. You will need to define your own customization for YCM by putting a ''.ycm_extra_conf.py'' file in your l4/pkg directory. Start with a copy of the original file that ships with YCM (''.vim/bundle/YouCompleteMe/cpp/ycm/.ycm_extra_conf.py'').
Set the ''flags'' array to contain a list of the L4Re compile flags that should be passed to Clang for compilation. You can get those flags by doing a
  $> make VERBOSE=1
for any of your L4Re packages and copying the flags from there.
The important part of .ycm_extra_conf.py looks like this for me:
# CHANGE THIS LIST OF FLAGS. YES, THIS IS THE DROID YOU HAVE BEEN LOOKING FOR.
flags = [
'-m32',
'-Wall',
'-fexceptions',
# THIS IS IMPORTANT! Without a "-std=<something>" flag, clang won't know which
# language to use when compiling headers. So it will guess. Badly. So C++
# headers will be compiled as C headers. You don't want that so ALWAYS specify
# a "-std=<something>".
# For a C project, you would set this to something like 'c99' instead of
# 'c++11'.
'-std=c++11',
# ...and the same thing goes for the magic -x option which specifies the
# language that the files to be compiled are written in. This is mostly
# relevant for c++ headers.
# For a C project, you would set this to 'c' instead of 'c++'.
'-x',
'c++',
'-DSYSTEM_x86_586_l4f',
'-DARCH_x86',
'-DCPUTYPE_586',
'-DL4API_l4f',
'-D_GNU_SOURCE',
'-D__L4',
'-I/home/doebel/src/tudos/l4/build/include/contrib/libstdc++-v3',
'-I/home/doebel/src/tudos/l4/build/include/contrib/libudis86',
'-I/home/doebel/src/tudos/l4/build/include/contrib/libiniparser',
'-I/home/doebel/src/tudos/l4/build/include/contrib/zlib',
'-I/home/doebel/src/tudos/l4/build/include/contrib/',
'-I/home/doebel/src/tudos/l4/build/include/x86/l4f',
'-I/home/doebel/src/tudos/l4/build/include/l4f',
'-I/home/doebel/src/tudos/l4/build/include/x86',
'-I/home/doebel/src/tudos/l4/build/include',
'-nostdinc',
'-I/home/doebel/src/tudos/l4/build/include/uclibc',
'-isystem /usr/lib/gcc/x86_64-linux-gnu/4.7/include',
'-isystem /usr/lib/gcc/x86_64-linux-gnu/4.7/include-fixed'
]
== Emacs / Auto-Complete-Clang ==
As I have too much time on my hands I even have a working completion setup for Emacs. Here I am using [https://github.com/Golevka/emacs-clang-complete-async autocomplete-clang-async]. Then in .emacs:
(defun my-ac-cc-mode-setup ()
  (add-to-list 'load-path "~/.emacs.d/ac-clang-async")
  (require 'auto-complete-clang-async)
  (setq ac-clang-complete-executable "~/.emacs.d/ac-clang-async/clang-complete")
  (setq ac-sources '(ac-source-clang-async))
  (let ((bname (buffer-file-name)))
    (cond
      ; L4Re-specific configuration
      ((string-match "l4/pkg" bname)
      (setq clang-include-dir-str "
/home/doebel/src/tudos/l4/build/include/contrib/libstdc++-v3
/home/doebel/src/tudos/l4/build/include/contrib/libudis86
/home/doebel/src/tudos/l4/build/include/contrib/libiniparser
/home/doebel/src/tudos/l4/build/include/contrib/zlib
/home/doebel/src/tudos/l4/build/include/contrib/
/home/doebel/src/tudos/l4/build/include/x86/l4f
/home/doebel/src/tudos/l4/build/include/l4f
/home/doebel/src/tudos/l4/build/include/x86
/home/doebel/src/tudos/l4/build/include
/home/doebel/src/tudos/l4/build/include/uclibc
/home/doebel/src/tudos/l4/build/include/contrib/libstdc++-v3
")
      (setq clang-pre-flags '("-nostdinc" "-g" "-std=c++11" "-m32" "-DSYSTEM_x86_586_l4f"
                              "-DARCH-x86" "-DCPUTYPE_586" "-DL4API_l4f" "-D_GNU_SOURCE" "-D__L4"
                              "-fexceptions" "-fno-omit-frame-pointer" "-fno-strict-aliasing"))
      (setq clang-add-flags '("-isystem /usr/lib/gcc/x86_64-linux-gnu/4.9/include"
                              "-isystem /usr/lib/gcc/x86_64-linux-gnu/4.9/include-fixed" ))
      )
      ; Everthing else (aka Linux programming)
    ((t) (setq clang-include-dir-str "
  /usr/include/c++/4.9
  /usr/include/x86_64-linux-gnu/c++/4.9
  /usr/include/c++/4.9/backward
  /usr/lib/gcc/x86_64-linux-gnu/4.9/include
  /usr/local/include
  /usr/lib/gcc/x86_64-linux-gnu/4.9/include-fixed
  /usr/include/x86_64-linux-gnu
  /usr/include
")
      (setq clang-pre-flags ())
      (setq clang-add-flags '("-x c++" "-g" "-std=c++11" "-msse4"))
      )
    ))
 
  (setq clang-iflags
          (mapcar (lambda (item) (concat "-I" item))
                  (split-string clang-include-dir-str))
          )
  (setq ac-clang-cflags (append clang-pre-flags clang-iflags clang-add-flags))
  (setq ac-clang-auto-save t)
  (ac-clang-launch-completion-process)
  )
(add-hook 'c-mode-common-hook 'my-ac-cc-mode-setup)
(add-hook 'c++-mode-hook 'my-ac-cc-mode-setup)


[[Category: Knowledge Base]]
[[Category: Knowledge Base]]

Latest revision as of 13:36, 26 November 2014

Eclipse

If you want to use Eclipse to work on the ComplexLab, you need to tell Eclipse where the include files are located and provide them in the correct order.

To simplify that task, you can import this project-settings using File -> Import -> C/C++ Project Settings. Afterwards you need to rebuild the index at <Your project> -> Index -> Rebuild. Note that this settings are specific for the ComplexLab and the x86 architecture.

This is a work in progress, so don't expect it to be perfect :-)

KDevelop

KDevelop requires you to set up an index file using absolute paths. This file is called .kdev_include_paths and should reside in the root directory of your L4Re checkout. Mine looks like this:

/home/doebel/src/tudos/src/build/include/x86
/home/doebel/src/tudos/src/build/include/x86/l4f
/home/doebel/src/tudos/src/build/include
/home/doebel/src/tudos/src/build/include/l4f
/home/doebel/src/tudos/src/build/include/uclibc
/home/doebel/src/tudos/src/build/include/contrib/acpica
/home/doebel/src/tudos/src/build/include/contrib/ankh_lwip
/home/doebel/src/tudos/src/build/include/contrib/boost-1_39-lite
/home/doebel/src/tudos/src/build/include/contrib/libiniparser
/home/doebel/src/tudos/src/build/include/contrib/libio-direct
/home/doebel/src/tudos/src/build/include/contrib/libio-io
/home/doebel/src/tudos/src/build/include/contrib/libpng
/home/doebel/src/tudos/src/build/include/contrib/libstdc++-v3
/home/doebel/src/tudos/src/build/include/contrib/libudis86
/home/doebel/src/tudos/src/build/include/contrib/lua
/home/doebel/src/tudos/src/build/include/contrib/lwip
/home/doebel/src/tudos/src/build/include/contrib/zlib

VIM / YouCompleteMe

VIM's excellent YouCompleteMe plugin provides C/C++ completion and works for L4Re with some tweaks. You will need to define your own customization for YCM by putting a .ycm_extra_conf.py file in your l4/pkg directory. Start with a copy of the original file that ships with YCM (.vim/bundle/YouCompleteMe/cpp/ycm/.ycm_extra_conf.py).

Set the flags array to contain a list of the L4Re compile flags that should be passed to Clang for compilation. You can get those flags by doing a

 $> make VERBOSE=1

for any of your L4Re packages and copying the flags from there.

The important part of .ycm_extra_conf.py looks like this for me:

# CHANGE THIS LIST OF FLAGS. YES, THIS IS THE DROID YOU HAVE BEEN LOOKING FOR.
flags = [
'-m32',
'-Wall',
'-fexceptions',
# THIS IS IMPORTANT! Without a "-std=<something>" flag, clang won't know which
# language to use when compiling headers. So it will guess. Badly. So C++
# headers will be compiled as C headers. You don't want that so ALWAYS specify
# a "-std=<something>". 
# For a C project, you would set this to something like 'c99' instead of
# 'c++11'.
'-std=c++11',
# ...and the same thing goes for the magic -x option which specifies the
# language that the files to be compiled are written in. This is mostly
# relevant for c++ headers.
# For a C project, you would set this to 'c' instead of 'c++'.
'-x',
'c++',
'-DSYSTEM_x86_586_l4f',
'-DARCH_x86',
'-DCPUTYPE_586',
'-DL4API_l4f',
'-D_GNU_SOURCE',
'-D__L4',
'-I/home/doebel/src/tudos/l4/build/include/contrib/libstdc++-v3',
'-I/home/doebel/src/tudos/l4/build/include/contrib/libudis86',
'-I/home/doebel/src/tudos/l4/build/include/contrib/libiniparser',
'-I/home/doebel/src/tudos/l4/build/include/contrib/zlib',
'-I/home/doebel/src/tudos/l4/build/include/contrib/',
'-I/home/doebel/src/tudos/l4/build/include/x86/l4f',
'-I/home/doebel/src/tudos/l4/build/include/l4f',
'-I/home/doebel/src/tudos/l4/build/include/x86',
'-I/home/doebel/src/tudos/l4/build/include',
'-nostdinc',
'-I/home/doebel/src/tudos/l4/build/include/uclibc',
'-isystem /usr/lib/gcc/x86_64-linux-gnu/4.7/include',
'-isystem /usr/lib/gcc/x86_64-linux-gnu/4.7/include-fixed'
]

Emacs / Auto-Complete-Clang

As I have too much time on my hands I even have a working completion setup for Emacs. Here I am using autocomplete-clang-async. Then in .emacs:

(defun my-ac-cc-mode-setup ()
  (add-to-list 'load-path "~/.emacs.d/ac-clang-async")
  (require 'auto-complete-clang-async)
  (setq ac-clang-complete-executable "~/.emacs.d/ac-clang-async/clang-complete")
  (setq ac-sources '(ac-source-clang-async))

  (let ((bname (buffer-file-name)))
    (cond
     ; L4Re-specific configuration
     ((string-match "l4/pkg" bname)
      (setq clang-include-dir-str "
/home/doebel/src/tudos/l4/build/include/contrib/libstdc++-v3
/home/doebel/src/tudos/l4/build/include/contrib/libudis86
/home/doebel/src/tudos/l4/build/include/contrib/libiniparser
/home/doebel/src/tudos/l4/build/include/contrib/zlib
/home/doebel/src/tudos/l4/build/include/contrib/
/home/doebel/src/tudos/l4/build/include/x86/l4f
/home/doebel/src/tudos/l4/build/include/l4f
/home/doebel/src/tudos/l4/build/include/x86
/home/doebel/src/tudos/l4/build/include
/home/doebel/src/tudos/l4/build/include/uclibc
/home/doebel/src/tudos/l4/build/include/contrib/libstdc++-v3
")
      (setq clang-pre-flags '("-nostdinc" "-g" "-std=c++11" "-m32" "-DSYSTEM_x86_586_l4f"
                              "-DARCH-x86" "-DCPUTYPE_586" "-DL4API_l4f" "-D_GNU_SOURCE" "-D__L4"
                              "-fexceptions" "-fno-omit-frame-pointer" "-fno-strict-aliasing"))
      (setq clang-add-flags '("-isystem /usr/lib/gcc/x86_64-linux-gnu/4.9/include"
                              "-isystem /usr/lib/gcc/x86_64-linux-gnu/4.9/include-fixed" ))
      )

     ; Everthing else (aka Linux programming)
    ((t) (setq clang-include-dir-str "
 /usr/include/c++/4.9
 /usr/include/x86_64-linux-gnu/c++/4.9
 /usr/include/c++/4.9/backward
 /usr/lib/gcc/x86_64-linux-gnu/4.9/include
 /usr/local/include
 /usr/lib/gcc/x86_64-linux-gnu/4.9/include-fixed
 /usr/include/x86_64-linux-gnu
 /usr/include
")
     (setq clang-pre-flags ())
     (setq clang-add-flags '("-x c++" "-g" "-std=c++11" "-msse4"))
     )
    ))
  
  (setq clang-iflags
         (mapcar (lambda (item) (concat "-I" item))
                 (split-string clang-include-dir-str))
         )
  (setq ac-clang-cflags (append clang-pre-flags clang-iflags clang-add-flags))

  (setq ac-clang-auto-save t)
  (ac-clang-launch-completion-process)
  )

(add-hook 'c-mode-common-hook 'my-ac-cc-mode-setup)
(add-hook 'c++-mode-hook 'my-ac-cc-mode-setup)