用于 OpenCV C++ 的 Emacs CEDET界面

发布于 2024-12-29 10:01:21 字数 3800 浏览 0 评论 0原文

所以,我已经使用 CEDET 一段时间了,总的来说,一切都运行得很好。 我正在从使用 C 转向使用 C++,特别是 OpenCV 2.3 (linux),但我遇到了问题。我正在使用 emacs24 和最新的开发版本的 CEDET。

它无法解析某些符号及其成员,例如:KeyPoint、Mat 等。

但是,许多函数符号都可以解析,例如 line()、imshow()、imread( ) 等。

我正在寻求有关如何调试我的设置错误的帮助,或者寻求已成功设置 opencv c++ api 的人。

这是我的相关 cedet 配置:

;; brian-cedet.el
;; Contains my personal configuration for CEDET

;; Loads for CEDET 
(load-file "/home/terranpro/code/cedet/common/cedet.el")

(add-to-list 'Info-default-directory-list
             (expand-file-name "~/code/cedet/common"))
(add-to-list 'Info-directory-list
             (expand-file-name "~/code/cedet/common"))

(add-to-list 'Info-directory-list
             (expand-file-name "~/code/cedet/semantic/doc"))
(add-to-list 'Info-directory-list
             (expand-file-name "~/code/cedet/eieio"))
(add-to-list 'Info-directory-list
             (expand-file-name "~/code/cedet/speedbar"))
(add-to-list 'Info-directory-list
             (expand-file-name "~/code/cedet/cogre"))
(add-to-list 'Info-directory-list
             (expand-file-name "~/code/cedet/ede"))
(add-to-list 'Info-directory-list
             (expand-file-name "~/code/cedet/srecode"))

(require 'ede)

(global-ede-mode t)

;;(semantic-load-enable-minimum-features)
(semantic-load-enable-code-helpers)
;;(semantic-load-enable-gaudy-code-helpers)
(semantic-load-enable-excessive-code-helpers)
;;(semantic-load-enable-semantic-debugging-helpers)

(require 'semantic-ia)

(require 'semantic-gcc)

(require 'semantic-sb)

(require 'semanticdb)
(global-semanticdb-minor-mode 1)

(require 'semanticdb-global)
(semanticdb-enable-gnu-global-databases 'c-mode)
(semanticdb-enable-gnu-global-databases 'c++-mode)

(require 'semantic-c)

(setq semantic-load-turn-useful-things-on t)

(semantic-add-system-include "/usr/include/glib-2.0" 'c-mode)
(semantic-add-system-include "/usr/include/glib-2.0" 'c++-mode)
(semantic-add-system-include "/usr/include/gtk-3.0" 'c-mode)
(semantic-add-system-include "/usr/include/gtk-3.0" 'c++-mode)

(semantic-add-system-include "/usr/local/include/" 'c-mode)
(semantic-add-system-include "/usr/local/include/" 'c++-mode)

(semantic-add-system-include "/usr/local/include/opencv" 'c-mode)
(semantic-add-system-include "/usr/local/include/opencv2" 'c++-mode)
(semantic-add-system-include "/usr/local/include/opencv" 'c-mode)
(semantic-add-system-include "/usr/local/include/opencv2" 'c++-mode)

(add-to-list 'semantic-lex-c-preprocessor-symbol-file 
         '"/usr/local/include/opencv2/core/types_c.h")
(add-to-list 'semantic-lex-c-preprocessor-symbol-file 
         '"/usr/local/include/opencv2/imgproc/types_c.h")

(add-to-list 'semantic-lex-c-preprocessor-symbol-map '("CV_PROP_RW" . ""))
(add-to-list 'semantic-lex-c-preprocessor-symbol-map '("CV_EXPORTS" . ""))
(add-to-list 'semantic-lex-c-preprocessor-symbol-map '("CV_EXPORTS_W_SIMPLE" . ""))

(defun my-cedet-hook ()
  (local-set-key [(control return)] 'semantic-ia-complete-symbol)
  (local-set-key "\C-c?" 'semantic-ia-complete-symbol-menu)
  (local-set-key "\C-c>" 'semantic-complete-analyze-inline)
  (local-set-key "\C-c=" 'semantic-decoration-include-visit)
  (local-set-key "\C-cj" 'semantic-ia-fast-jump)
  (local-set-key "\C-cq" 'semantic-ia-show-doc)
  (local-set-key "\C-cs" 'semantic-ia-show-summary)
  (local-set-key "\C-cp" 'semantic-analyze-proto-impl-toggle)
  (local-set-key "\C-c+" 'semantic-tag-folding-show-block)
  (local-set-key "\C-c-" 'semantic-tag-folding-fold-block)
  (local-set-key "\C-c\C-c+" 'semantic-tag-folding-show-all)
  (local-set-key "\C-c\C-c-" 'semantic-tag-folding-fold-all))
(add-hook 'c-mode-common-hook 'my-cedet-hook)
(add-hook 'emacs-lisp-mode-hook 'my-cedet-hook)
(add-hook 'lisp-interaction-mode-hook 'my-cedet-hook)

(global-semantic-tag-folding-mode 1)

So, I have used CEDET for awhile now, and things work pretty well in general.
I'm moving from using it with C to C++, specifically for OpenCV 2.3 (linux) and I'm running into problems. I'm using emacs24 with the latest dev version of CEDET.

It is unable to parse some symbols and their members, like: KeyPoint, Mat, etc.

Many of the function symbols ARE parsed however, such as line(), imshow(), imread(), etc.

I'm looking for help on how to debug what's wrong with my setup, or someone who has successfully setup opencv c++ api.

Here is my relevant cedet config:

;; brian-cedet.el
;; Contains my personal configuration for CEDET

;; Loads for CEDET 
(load-file "/home/terranpro/code/cedet/common/cedet.el")

(add-to-list 'Info-default-directory-list
             (expand-file-name "~/code/cedet/common"))
(add-to-list 'Info-directory-list
             (expand-file-name "~/code/cedet/common"))

(add-to-list 'Info-directory-list
             (expand-file-name "~/code/cedet/semantic/doc"))
(add-to-list 'Info-directory-list
             (expand-file-name "~/code/cedet/eieio"))
(add-to-list 'Info-directory-list
             (expand-file-name "~/code/cedet/speedbar"))
(add-to-list 'Info-directory-list
             (expand-file-name "~/code/cedet/cogre"))
(add-to-list 'Info-directory-list
             (expand-file-name "~/code/cedet/ede"))
(add-to-list 'Info-directory-list
             (expand-file-name "~/code/cedet/srecode"))

(require 'ede)

(global-ede-mode t)

;;(semantic-load-enable-minimum-features)
(semantic-load-enable-code-helpers)
;;(semantic-load-enable-gaudy-code-helpers)
(semantic-load-enable-excessive-code-helpers)
;;(semantic-load-enable-semantic-debugging-helpers)

(require 'semantic-ia)

(require 'semantic-gcc)

(require 'semantic-sb)

(require 'semanticdb)
(global-semanticdb-minor-mode 1)

(require 'semanticdb-global)
(semanticdb-enable-gnu-global-databases 'c-mode)
(semanticdb-enable-gnu-global-databases 'c++-mode)

(require 'semantic-c)

(setq semantic-load-turn-useful-things-on t)

(semantic-add-system-include "/usr/include/glib-2.0" 'c-mode)
(semantic-add-system-include "/usr/include/glib-2.0" 'c++-mode)
(semantic-add-system-include "/usr/include/gtk-3.0" 'c-mode)
(semantic-add-system-include "/usr/include/gtk-3.0" 'c++-mode)

(semantic-add-system-include "/usr/local/include/" 'c-mode)
(semantic-add-system-include "/usr/local/include/" 'c++-mode)

(semantic-add-system-include "/usr/local/include/opencv" 'c-mode)
(semantic-add-system-include "/usr/local/include/opencv2" 'c++-mode)
(semantic-add-system-include "/usr/local/include/opencv" 'c-mode)
(semantic-add-system-include "/usr/local/include/opencv2" 'c++-mode)

(add-to-list 'semantic-lex-c-preprocessor-symbol-file 
         '"/usr/local/include/opencv2/core/types_c.h")
(add-to-list 'semantic-lex-c-preprocessor-symbol-file 
         '"/usr/local/include/opencv2/imgproc/types_c.h")

(add-to-list 'semantic-lex-c-preprocessor-symbol-map '("CV_PROP_RW" . ""))
(add-to-list 'semantic-lex-c-preprocessor-symbol-map '("CV_EXPORTS" . ""))
(add-to-list 'semantic-lex-c-preprocessor-symbol-map '("CV_EXPORTS_W_SIMPLE" . ""))

(defun my-cedet-hook ()
  (local-set-key [(control return)] 'semantic-ia-complete-symbol)
  (local-set-key "\C-c?" 'semantic-ia-complete-symbol-menu)
  (local-set-key "\C-c>" 'semantic-complete-analyze-inline)
  (local-set-key "\C-c=" 'semantic-decoration-include-visit)
  (local-set-key "\C-cj" 'semantic-ia-fast-jump)
  (local-set-key "\C-cq" 'semantic-ia-show-doc)
  (local-set-key "\C-cs" 'semantic-ia-show-summary)
  (local-set-key "\C-cp" 'semantic-analyze-proto-impl-toggle)
  (local-set-key "\C-c+" 'semantic-tag-folding-show-block)
  (local-set-key "\C-c-" 'semantic-tag-folding-fold-block)
  (local-set-key "\C-c\C-c+" 'semantic-tag-folding-show-all)
  (local-set-key "\C-c\C-c-" 'semantic-tag-folding-fold-all))
(add-hook 'c-mode-common-hook 'my-cedet-hook)
(add-hook 'emacs-lisp-mode-hook 'my-cedet-hook)
(add-hook 'lisp-interaction-mode-hook 'my-cedet-hook)

(global-semantic-tag-folding-mode 1)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

两仪 2025-01-05 10:01:21

我现在有一个工作配置;感谢来自 cedet-devel 邮件列表的 Alex Ott 和 David Engster。为了注意他们的更正,我的配置中有一些“不需要并且可能有害”的行。更新配置后,删除 ~/.semanticdb 中的所有文件并重新启动 emacs,一切都按预期进行!

我还提供了一个用于测试配置的示例 cpp 文件。谢谢你们!

(load-file "/home/terranpro/code/cedet/common/cedet.el")

(require 'ede)

(global-ede-mode t)

;;(semantic-load-enable-minimum-features)
(semantic-load-enable-code-helpers)
;;(semantic-load-enable-gaudy-code-helpers)
(semantic-load-enable-excessive-code-helpers)
;;(semantic-load-enable-semantic-debugging-helpers)

;; CEDET-devel mailing list said these werent needed
;; and possibly hurtful
;;(require 'semantic-ia)

;;(require 'semantic-gcc)

;;(require 'semantic-sb)

;;(require 'semanticdb)
;;(global-semanticdb-minor-mode 1)

;;(require 'semanticdb-global)

(semanticdb-enable-gnu-global-databases 'c-mode)
(semanticdb-enable-gnu-global-databases 'c++-mode)

(require 'semantic-c)

(setq semantic-load-turn-useful-things-on t)

(semantic-add-system-include "/usr/local/include/" 'c-mode)
(semantic-add-system-include "/usr/local/include/" 'c++-mode)

(add-to-list 'semantic-lex-c-preprocessor-symbol-file 
         '"/usr/local/include/opencv2/core/types_c.h")
(add-to-list 'semantic-lex-c-preprocessor-symbol-file 
         '"/usr/local/include/opencv2/imgproc/types_c.h")

(add-to-list 'semantic-lex-c-preprocessor-symbol-map '("CV_PROP_RW" . ""))
(add-to-list 'semantic-lex-c-preprocessor-symbol-map '("CV_EXPORTS" . ""))
(add-to-list 'semantic-lex-c-preprocessor-symbol-map '("CV_EXPORTS_W_SIMPLE" . ""))
(add-to-list 'semantic-lex-c-preprocessor-symbol-map '("CV_EXPORTS_W" . ""))
(add-to-list 'semantic-lex-c-preprocessor-symbol-map '("CV_EXPORTS_W_MAP" . ""))
(add-to-list 'semantic-lex-c-preprocessor-symbol-map '("CV_INLINE" . ""))

(defun my-cedet-hook ()
  (local-set-key [(control return)] 'semantic-ia-complete-symbol)
  (local-set-key "\C-c?" 'semantic-ia-complete-symbol-menu)
  (local-set-key "\C-c>" 'semantic-complete-analyze-inline)
  (local-set-key "\C-c=" 'semantic-decoration-include-visit)
  (local-set-key "\C-cj" 'semantic-ia-fast-jump)
  (local-set-key "\C-cq" 'semantic-ia-show-doc)
  (local-set-key "\C-cs" 'semantic-ia-show-summary)
  (local-set-key "\C-cp" 'semantic-analyze-proto-impl-toggle)
  (local-set-key "\C-c+" 'semantic-tag-folding-show-block)
  (local-set-key "\C-c-" 'semantic-tag-folding-fold-block)
  (local-set-key "\C-c\C-c+" 'semantic-tag-folding-show-all)
  (local-set-key "\C-c\C-c-" 'semantic-tag-folding-fold-all))
(add-hook 'c-mode-common-hook 'my-cedet-hook)
(add-hook 'emacs-lisp-mode-hook 'my-cedet-hook)
(add-hook 'lisp-interaction-mode-hook 'my-cedet-hook)

(global-semantic-tag-folding-mode 1)

以及CPP测试文件:

#include <stdio.h>
#include <vector>
#include <string>
#include <opencv2/opencv.hpp>
#include <opencv2/core/core.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/features2d/features2d.hpp>
#include <opencv2/highgui/highgui.hpp>

using namespace cv;
using namespace std;

int main(int argc, char **argv)
{
  KeyPoint k;
  Mat m;

  // m should have members like m.clone()
  // k has members like k.pt (Point2f pt)

  return 0;
}

I have a working configuration now; thanks to Alex Ott and David Engster from cedet-devel mailing list. To note their corrections, there were some lines in my configuration that were ' not needed and possibly hurtful.' After updating the config, deleting all files in ~/.semanticdb and restarting emacs, things are working as expected!

I've also included a sample cpp file for testing the configuration. Thanks guys!

(load-file "/home/terranpro/code/cedet/common/cedet.el")

(require 'ede)

(global-ede-mode t)

;;(semantic-load-enable-minimum-features)
(semantic-load-enable-code-helpers)
;;(semantic-load-enable-gaudy-code-helpers)
(semantic-load-enable-excessive-code-helpers)
;;(semantic-load-enable-semantic-debugging-helpers)

;; CEDET-devel mailing list said these werent needed
;; and possibly hurtful
;;(require 'semantic-ia)

;;(require 'semantic-gcc)

;;(require 'semantic-sb)

;;(require 'semanticdb)
;;(global-semanticdb-minor-mode 1)

;;(require 'semanticdb-global)

(semanticdb-enable-gnu-global-databases 'c-mode)
(semanticdb-enable-gnu-global-databases 'c++-mode)

(require 'semantic-c)

(setq semantic-load-turn-useful-things-on t)

(semantic-add-system-include "/usr/local/include/" 'c-mode)
(semantic-add-system-include "/usr/local/include/" 'c++-mode)

(add-to-list 'semantic-lex-c-preprocessor-symbol-file 
         '"/usr/local/include/opencv2/core/types_c.h")
(add-to-list 'semantic-lex-c-preprocessor-symbol-file 
         '"/usr/local/include/opencv2/imgproc/types_c.h")

(add-to-list 'semantic-lex-c-preprocessor-symbol-map '("CV_PROP_RW" . ""))
(add-to-list 'semantic-lex-c-preprocessor-symbol-map '("CV_EXPORTS" . ""))
(add-to-list 'semantic-lex-c-preprocessor-symbol-map '("CV_EXPORTS_W_SIMPLE" . ""))
(add-to-list 'semantic-lex-c-preprocessor-symbol-map '("CV_EXPORTS_W" . ""))
(add-to-list 'semantic-lex-c-preprocessor-symbol-map '("CV_EXPORTS_W_MAP" . ""))
(add-to-list 'semantic-lex-c-preprocessor-symbol-map '("CV_INLINE" . ""))

(defun my-cedet-hook ()
  (local-set-key [(control return)] 'semantic-ia-complete-symbol)
  (local-set-key "\C-c?" 'semantic-ia-complete-symbol-menu)
  (local-set-key "\C-c>" 'semantic-complete-analyze-inline)
  (local-set-key "\C-c=" 'semantic-decoration-include-visit)
  (local-set-key "\C-cj" 'semantic-ia-fast-jump)
  (local-set-key "\C-cq" 'semantic-ia-show-doc)
  (local-set-key "\C-cs" 'semantic-ia-show-summary)
  (local-set-key "\C-cp" 'semantic-analyze-proto-impl-toggle)
  (local-set-key "\C-c+" 'semantic-tag-folding-show-block)
  (local-set-key "\C-c-" 'semantic-tag-folding-fold-block)
  (local-set-key "\C-c\C-c+" 'semantic-tag-folding-show-all)
  (local-set-key "\C-c\C-c-" 'semantic-tag-folding-fold-all))
(add-hook 'c-mode-common-hook 'my-cedet-hook)
(add-hook 'emacs-lisp-mode-hook 'my-cedet-hook)
(add-hook 'lisp-interaction-mode-hook 'my-cedet-hook)

(global-semantic-tag-folding-mode 1)

And the CPP test file:

#include <stdio.h>
#include <vector>
#include <string>
#include <opencv2/opencv.hpp>
#include <opencv2/core/core.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/features2d/features2d.hpp>
#include <opencv2/highgui/highgui.hpp>

using namespace cv;
using namespace std;

int main(int argc, char **argv)
{
  KeyPoint k;
  Mat m;

  // m should have members like m.clone()
  // k has members like k.pt (Point2f pt)

  return 0;
}
幸福丶如此 2025-01-05 10:01:21

看起来,语义解析器无法解析类声明 - 它将其视为 CV_EXPORTS Mat 而不是 Mat 本身,尽管 CV_EXPORTS 应该是展开为空字符串。我使用了以下配置,它对于 C 代码运行良好,但不适用于 C++。我建议您写信给 cedet-devel 邮件列表并附上示例 - 只需写在那里,如果有必要,我将为您的邮件提供更多评论...

(ede-cpp-root-project "OpenCV/C++ test"
     :name "OpenCV/C++ test"
     :file "/Users/ott/development/opencv-examples/cpp/CMakeLists.txt"
     :include-path '("/"
                  )
     :system-include-path '("/opt/local/include"
                     "/opt/local/include/opencv"
                     "/opt/local/include/opencv2")
     :spp-table '(
                  ("CV_PROP_RW" . "")
                  ("CV_EXPORTS" . "")
                  ("CV_EXPORTS_W_SIMPLE" . "")
               ("CV_EXPORTS_W" . "")
               ("CV_EXPORTS_W_MAP" . "")
               ("CV_INLINE" . ""))
     :local-variables (list
               (cons 'semantic-lex-c-preprocessor-symbol-file
                 (cons "/opt/local/include/opencv2/core/types_c.h"
                   (cons "/opt/local/include/opencv2/imgproc/types_c.h"
                     semantic-lex-c-preprocessor-symbol-file)))))

It looks like, the Semantic parser couldn't parse class declaration - it sees it as CV_EXPORTS Mat not as Mat itself, although CV_EXPORTS should be expanded into empty string. I've used following configuration and it worked fine for C code, but not for C++. I suggest that you write to cedet-devel mailing list with examples - just write there, and if necessary, I'll provide more comments for your mail...

(ede-cpp-root-project "OpenCV/C++ test"
     :name "OpenCV/C++ test"
     :file "/Users/ott/development/opencv-examples/cpp/CMakeLists.txt"
     :include-path '("/"
                  )
     :system-include-path '("/opt/local/include"
                     "/opt/local/include/opencv"
                     "/opt/local/include/opencv2")
     :spp-table '(
                  ("CV_PROP_RW" . "")
                  ("CV_EXPORTS" . "")
                  ("CV_EXPORTS_W_SIMPLE" . "")
               ("CV_EXPORTS_W" . "")
               ("CV_EXPORTS_W_MAP" . "")
               ("CV_INLINE" . ""))
     :local-variables (list
               (cons 'semantic-lex-c-preprocessor-symbol-file
                 (cons "/opt/local/include/opencv2/core/types_c.h"
                   (cons "/opt/local/include/opencv2/imgproc/types_c.h"
                     semantic-lex-c-preprocessor-symbol-file)))))
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文