<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wikemacs.org/index.php?action=history&amp;feed=atom&amp;title=C-ide</id>
	<title>C-ide - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://wikemacs.org/index.php?action=history&amp;feed=atom&amp;title=C-ide"/>
	<link rel="alternate" type="text/html" href="https://wikemacs.org/index.php?title=C-ide&amp;action=history"/>
	<updated>2026-04-10T06:13:17Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.35.14</generator>
	<entry>
		<id>https://wikemacs.org/index.php?title=C-ide&amp;diff=46843&amp;oldid=prev</id>
		<title>Elvince: c and cpp ide</title>
		<link rel="alternate" type="text/html" href="https://wikemacs.org/index.php?title=C-ide&amp;diff=46843&amp;oldid=prev"/>
		<updated>2014-11-06T10:29:56Z</updated>

		<summary type="html">&lt;p&gt;c and cpp ide&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;C/C++ Development Environment for Emacs&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In this guide, I will help you to setup an efficient working C/C++ environment. Despite looking long, the setup is short and easy (mostly copy/paste Emacs Lisp code into your init.el); most of the guide are explanations and demonstrations of many useful features. Following this guide, you should be able to browse the Linux kernel source tree inside Emacs effortlessly, such as jump to definition/references at cursor, go back and forth between jumping points, finding any file instantly, switching between .h and .c/.cpp. We include demos in the end.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Source code navigation =&lt;br /&gt;
&lt;br /&gt;
== Install GNU Global ==&lt;br /&gt;
&lt;br /&gt;
Install [http://www.gnu.org/software/global/ GNU Global]:&lt;br /&gt;
&lt;br /&gt;
    apt-get install global &lt;br /&gt;
&lt;br /&gt;
Or get the sources [http://www.gnu.org/software/global/download.html here] and for windows users, [http://adoxa.altervista.org/global/ get the win32 port].&lt;br /&gt;
&lt;br /&gt;
Install [https://github.com/leoliu/ggtags ggtags] from [[MELPA]] and add this snippet to your init file:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;lisp&amp;quot;&amp;gt;&lt;br /&gt;
(require 'ggtags)&lt;br /&gt;
(add-hook 'c-mode-common-hook&lt;br /&gt;
          (lambda ()&lt;br /&gt;
            (when (derived-mode-p 'c-mode 'c++-mode 'java-mode 'asm-mode)&lt;br /&gt;
              (ggtags-mode 1))))&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And define some keybinding if you wish:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;lisp&amp;quot;&amp;gt;&lt;br /&gt;
(define-key ggtags-mode-map (kbd &amp;quot;C-c g s&amp;quot;) 'ggtags-find-other-symbol)&lt;br /&gt;
(define-key ggtags-mode-map (kbd &amp;quot;C-c g h&amp;quot;) 'ggtags-view-tag-history)&lt;br /&gt;
(define-key ggtags-mode-map (kbd &amp;quot;C-c g r&amp;quot;) 'ggtags-find-reference)&lt;br /&gt;
(define-key ggtags-mode-map (kbd &amp;quot;C-c g f&amp;quot;) 'ggtags-find-file)&lt;br /&gt;
(define-key ggtags-mode-map (kbd &amp;quot;C-c g c&amp;quot;) 'ggtags-create-tags)&lt;br /&gt;
(define-key ggtags-mode-map (kbd &amp;quot;C-c g u&amp;quot;) 'ggtags-update-tags)&lt;br /&gt;
&lt;br /&gt;
(define-key ggtags-mode-map (kbd &amp;quot;M-,&amp;quot;) 'pop-tag-mark)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Use helm-gtags ==&lt;br /&gt;
&lt;br /&gt;
[[helm]] is a nice interactive interface to many tools, so [https://github.com/syohex/emacs-helm-gtags helm-gtags] is very handy. Remember to setup Helm before using helm-gtags. When includes the above file in your ~/.emacs.d, remember to add (require 'setup-helm) to your init.el. &lt;br /&gt;
&lt;br /&gt;
Basic config:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;lisp&amp;quot;&amp;gt;&lt;br /&gt;
(setq&lt;br /&gt;
 helm-gtags-ignore-case t&lt;br /&gt;
 helm-gtags-auto-update t&lt;br /&gt;
 helm-gtags-use-input-at-cursor t&lt;br /&gt;
 helm-gtags-pulse-at-cursor t&lt;br /&gt;
 helm-gtags-prefix-key &amp;quot;\C-cg&amp;quot;&lt;br /&gt;
 helm-gtags-suggested-key-mapping t&lt;br /&gt;
 )&lt;br /&gt;
&lt;br /&gt;
(require 'helm-gtags)&lt;br /&gt;
;; Enable helm-gtags-mode&lt;br /&gt;
(add-hook 'dired-mode-hook 'helm-gtags-mode)&lt;br /&gt;
(add-hook 'eshell-mode-hook 'helm-gtags-mode)&lt;br /&gt;
(add-hook 'c-mode-hook 'helm-gtags-mode)&lt;br /&gt;
(add-hook 'c++-mode-hook 'helm-gtags-mode)&lt;br /&gt;
(add-hook 'asm-mode-hook 'helm-gtags-mode)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And some keybindings:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;lisp&amp;quot;&amp;gt;&lt;br /&gt;
(define-key helm-gtags-mode-map (kbd &amp;quot;C-c g a&amp;quot;) 'helm-gtags-tags-in-this-function)&lt;br /&gt;
(define-key helm-gtags-mode-map (kbd &amp;quot;M-s&amp;quot;) 'helm-gtags-select)&lt;br /&gt;
(define-key helm-gtags-mode-map (kbd &amp;quot;M-.&amp;quot;) 'helm-gtags-dwim)&lt;br /&gt;
(define-key helm-gtags-mode-map (kbd &amp;quot;M-,&amp;quot;) 'helm-gtags-pop-stack)&lt;br /&gt;
(define-key helm-gtags-mode-map (kbd &amp;quot;C-c &amp;lt;&amp;quot;) 'helm-gtags-previous-history)&lt;br /&gt;
(define-key helm-gtags-mode-map (kbd &amp;quot;C-c &amp;gt;&amp;quot;) 'helm-gtags-next-history)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Create the tags ==&lt;br /&gt;
&lt;br /&gt;
Before using the ggtags or helm-gtags, remember to create a GTAGS database by running the command '''ggtags-create-tags&lt;br /&gt;
'''.&lt;br /&gt;
&lt;br /&gt;
Or run gtags at your project root in terminal: &lt;br /&gt;
&lt;br /&gt;
    $ cd /path/to/project/root&lt;br /&gt;
    $ gtags&lt;br /&gt;
&lt;br /&gt;
After this, 3 files are created: &lt;br /&gt;
&lt;br /&gt;
* GTAGS: definition database&lt;br /&gt;
* GRTAGS: reference database&lt;br /&gt;
* GPATH: path name database&lt;br /&gt;
&lt;br /&gt;
== Usage ==&lt;br /&gt;
&lt;br /&gt;
* '''C-M-f''' runs forward-sexp, move forward over a balanced expression that can be a pair or a symbol.&lt;br /&gt;
* '''C-M-b''' runs backward-sexp, move backward over a balanced expression that can be a pair or a symbol. &lt;br /&gt;
* '''C-M-k''' runs kill-sexp, kill balanced expression forward that can be a pair or a symbol.&lt;br /&gt;
* '''C-M-&amp;lt;SPC&amp;gt;''' or '''C-M-@''' runs mark-sexp, put mark after following expression that can be a pair or a symbol. &lt;br /&gt;
* '''C-M-a''' runs beginning-of-defun, which moves point to beginning of a function.&lt;br /&gt;
* '''C-M-e''' is end-of-defun.&lt;br /&gt;
* '''C-M-h''' runs mark-defun, which put a region around whole current or following function.&lt;br /&gt;
&lt;br /&gt;
= Find definitions in current buffer =&lt;br /&gt;
&lt;br /&gt;
The Imenu facility offers a way to find the major definitions, such as function definitions, variable definitions in a file by name. ggtags can integrate Imenu:&lt;br /&gt;
&lt;br /&gt;
    (setq-local imenu-create-index-function #'ggtags-build-imenu-index)&lt;br /&gt;
&lt;br /&gt;
If you use Helm, use '''helm-semantic-or-imenu'''. You can use it as an outline tree like in other IDEs.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Find definitions in project =&lt;br /&gt;
&lt;br /&gt;
Using gtags: by default, '''M-.''' runs ggtags-find-tag-dwim when ggtags-mode is enabled. The command ggtags-find-tag-dwim jump to tag base on context:&lt;br /&gt;
*        If the tag at point is a definition, ggtags jumps to a reference. If there is more than one reference, it displays a list of references.&lt;br /&gt;
*       If the tag at point is a reference, ggtags jumps to tag definition.&lt;br /&gt;
*      If the tag at point is an include header, it jumps to that header.&lt;br /&gt;
&lt;br /&gt;
You can jump back to original location where you invoked ggtags-find-tag-dwim by '''M-,''', which runs pop-tag-mark (if you follow my key bindings).&lt;br /&gt;
&lt;br /&gt;
You can also find arbitrary tag definition when invoking M-. on blank space. A prompt asks you for tag pattern, which is a regexp.&lt;br /&gt;
&lt;br /&gt;
If ggtags gives you a list of candidates, you can use M-n to move to next candidate and M-p to move back previous candidate. Use M-g s to invoke Isearch on candidate buffer list&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Using '''helm-gtags''': If key bindings are properly setup as above, M-. runs helm-gtags-dwim, which behaves the same as ggtags-find-tag-dwim. Similarly, you jump back to original location by using M-,, which runs tags-loop-continue (Emacs default).&lt;br /&gt;
&lt;br /&gt;
helm-gtags provides a really nice feature that uses Helm to display all available tags in a project and incrementally filtering, and is really fast using helm-gtags-select, which is bound to M-s in my setup above. This is useful when you want to explore tags in unfamiliar project.&lt;br /&gt;
&lt;br /&gt;
= Find references in project =&lt;br /&gt;
&lt;br /&gt;
Using helm-gtags: Either run helm-gtags-dwim or helm-gtags-find-rtags, bound to C-c g r, which only finds references.&lt;br /&gt;
&lt;br /&gt;
= Find functions that current functions call =&lt;br /&gt;
&lt;br /&gt;
If you want to list all the functions that the current function - the function that point is inside - calls, you can do that with helm-gtags-tags-in-this-function, which is bound to C-c g a in my setup. &lt;br /&gt;
&lt;br /&gt;
= Find files in project =&lt;br /&gt;
&lt;br /&gt;
== Using projectile ==&lt;br /&gt;
&lt;br /&gt;
[[projectile]] is a very nice and complete solution.&lt;br /&gt;
&lt;br /&gt;
== Using ggtags ==&lt;br /&gt;
&lt;br /&gt;
Run ggtags-find-file&lt;br /&gt;
&lt;br /&gt;
= Browse source tree with Speedbar file browser =&lt;br /&gt;
&lt;br /&gt;
You can use many packages for that, such as [[speedbar]] or [[sr-speedbar]] (in MELPA) to have the tree in the same frame.&lt;br /&gt;
&lt;br /&gt;
= General completion with company-mode =&lt;br /&gt;
&lt;br /&gt;
See [[company-mode]].&lt;br /&gt;
&lt;br /&gt;
Besides,  ''company-c-headers'' provides auto-completion for C/C++ headers using Company. After installing from MELPA, set it up: &lt;br /&gt;
 &lt;br /&gt;
    (add-to-list 'company-backends 'company-c-headers)&lt;br /&gt;
&lt;br /&gt;
= CEDET =&lt;br /&gt;
&lt;br /&gt;
[[CEDET]]&lt;br /&gt;
&lt;br /&gt;
= Project management with EDE =&lt;br /&gt;
&lt;br /&gt;
[[EDE]]&lt;br /&gt;
&lt;br /&gt;
= See also =&lt;br /&gt;
&lt;br /&gt;
The source of this page with many demos: http://tuhdo.github.io/c-ide.html&lt;br /&gt;
&lt;br /&gt;
[[Category:c-mode]]&lt;br /&gt;
[[Category:Programming]]&lt;br /&gt;
[[Category:Navigation]]&lt;br /&gt;
[[Category:Cpp]]&lt;/div&gt;</summary>
		<author><name>Elvince</name></author>
	</entry>
</feed>