首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >C预处理器定义没有被Cedet/Semantic考虑

C预处理器定义没有被Cedet/Semantic考虑
EN

Stack Overflow用户
提问于 2011-09-04 15:34:06
回答 1查看 1.2K关注 0票数 3

我试图在我的Linux内核开发项目中使用Emacs作为IDE。因此,我安装了CEDET和GNU Global (Gtag),没有任何问题。

当我打开属于我的Linux内核源代码文件夹的C源代码时,会自动检测到linux项目。正确突出显示函数、变量、标头和其他关键字。

通过~/..emacs文件,我配置了语义的代码完成和intellisense。所以当我按C键时,代码完成菜单就会出现,我可以选择需要什么。

问题是当我使用预处理器定义时,intellisense系统显示当前位置上的菜单,但在调用(C-)时没有检测到正确的内容。即使我关闭并重新启动emacs,也会复制相同的行为。

测试代码是:

//--------------------------------------

代码语言:javascript
复制
typedef struct
{
     int p1;

        #ifdef __KERNEL__

            int p2;

        #endif

        #ifdef USE1

             char p3;

          #endif

#ifdef __LINUX_ARM_ARCH__

   int p4;

#endif

}OBJ;

OBJ g_obj;

//--------------------------------------

LINUX_ARM_ARCH内核、USE1和USE1已经定义如下:

代码语言:javascript
复制
__KERNEL__ : (add-to-list 'semantic-lex-c-preprocessor-symbol-map '("__KERNEL__" . "")) in .emacs
USE1 : defined in a header file included by the current C source file.
__LINUX_ARM_ARCH__ : (add-to-list 'semantic-lex-c-preprocessor-symbol-file "/home/abdellatif/kernel/include/generated/autoconf.h") in .emacs

在.emacs文件中,我还添加了GCC交叉编译器(GCC用于ARM)所需的所有必需的包含和定义,以构建内核项目。

我也试图强迫语义使用GCC交叉编译器命令行来代替GCC对系统进行正确的预处理,但还没有找到如何实现的方法。

“M语义-c-描述-环境”命令显示正确的包含路径和定义(在.emacs中设置)。但GCC所界定的制度也被列举出来。

.emacs文件和软件版本如下所示。

欢迎任何帮助或暗示:)最好的问候

代码语言:javascript
复制
############# Software versions #############

- Emacs (23.2.1)
- Ubuntu machine (natty, 11.04)
- Cedet 1.0 (from http://cedet.sourceforge.net/)
代码语言:javascript
复制
############# .emacs #############

;load CEDET

(load-file "~/Documents/my_emacs/cedet-1.0/common/cedet.el")

(require 'ede)

(global-ede-mode t)
; turn on which-func support (plus all other code helpers)
(semantic-load-enable-gaudy-code-helpers)
(semantic-load-enable-excessive-code-helpers)

; turn on all "useful" features
(setq semantic-load-turn-useful-things-on t)

(setq-mode-local c-mode
         semanticdb-find-default-throttle
         '(project unloaded system recursive))

;init names completion, and displaying of information for tags & classes
(require 'semantic-ia)

;preprocessing of source code

(require 'semantic-c)

(semantic-reset-system-include 'c-mode)
(semantic-reset-system-include 'c++-mode)
(semantic-add-system-include "/home/abdellatif/toolchain/arm-eabi-4.4.3/lib/gcc/arm-eabi/4.4.3/include" 'c-mode)
(semantic-add-system-include "/home/abdellatif/kernel/arch/arm/include" 'c-mode)
(semantic-add-system-include "/home/abdellatif/kernel/include" 'c-mode)
(semantic-add-system-include "/home/abdellatif/kernel/arch/arm/mach-omap2/include" 'c-mode)
(semantic-add-system-include "/home/abdellatif/kernel/arch/arm/plat-omap/include" 'c-mode)
(add-to-list 'semantic-lex-c-preprocessor-symbol-file "/home/abdellatif/kernel/include/generated/autoconf.h")
(add-to-list 'semantic-lex-c-preprocessor-symbol-map '("__KERNEL__" . ""))
(add-to-list 'semantic-lex-c-preprocessor-symbol-map '("__LINUX_ARM_ARCH__" . "7"))
(add-to-list 'semantic-lex-c-preprocessor-symbol-map '("KBUILD_STR(s)" . "#s"))
(add-to-list 'semantic-lex-c-preprocessor-symbol-map '("KBUILD_BASENAME" . "KBUILD_STR(main)"))
(add-to-list 'semantic-lex-c-preprocessor-symbol-map '("KBUILD_MODNAME" . "KBUILD_STR(main)"))

;semantic integration with imenu (display of a menu with a list of functions, variables, and other tags)
(defun my-semantic-hook ()
  (imenu-add-to-menubar "TAGS"))
(add-hook 'semantic-init-hooks 'my-semantic-hook)

;names completion (semantic commands)
(defun my-cedet-hook ()
 (local-set-key [(control return)] 'semantic-ia-complete-symbol)
  (local-set-key "\C-x " 'semantic-ia-complete-symbol-menu)
   (local-set-key "\C-x\r" 'gtags-find-tag-from-here))
(add-hook 'c-mode-common-hook 'my-cedet-hook)

;navigating in source code
(semantic-mru-bookmark-mode 1)

;tell semantic to store its tags database between sessions here
(require 'semanticdb)
(setq-default semanticdb-default-save-directory "~/.semantic.cache")
(setq-default semanticdb-default-system-save-directory "~/.semantic.cache")

;allow Semanticdb use databases generated by global(gtags)
(require 'semanticdb-global)
(semanticdb-enable-gnu-global-databases 'c-mode)
EN

回答 1

Stack Overflow用户

发布于 2011-11-08 01:21:21

  1. 您应该从主线获得cedet:

bzr://cedet.bzr.sourceforge.net/bzrroot/cedet/code/trunk/

对于处理recently.

  • After的预处理程序有几个修复程序,可以更改语义-lex-c-预处理-符号-文件列表以及类似的内容,您应该删除语义缓存,并允许它从头开始重新创建它。
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/7300266

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档