如何为 C++ 创建 EDE 项目

发布于 2025-01-07 10:50:42 字数 1608 浏览 0 评论 0原文

我一直在尝试为 C++ (emacs24 + 内置 CEDET)建立一个 EDE 项目,但我开始变得绝望,因为我似乎找不到我想要生成 makefile 的方式。我对 Emacs 还比较陌生。 我将尝试描述我正在做的事情:

我有一个玩具项目,如下所示:

main.cpp
other/
  Utils.cpp 
  Utils.h
  CGrabBuffer.cpp
  CGrabBuffer.h

main.cpp 包含“other/”目录中的两个 .h。以下是我使用这个简单的目录设置来设置 EDE 项目所遵循的步骤:

  • 在 emacs 中打开 main.cpp 并执行 Mx ede-new ;类型:制作;名称:主项目
  • 打开“其他”目录中的文件之一并执行 Mx ede-new ;类型:制作;名称:aux-proj。
  • 现在是时候创建目标了(我认为在本例中是三个):
    • 在 main.cpp 缓冲区上:Mx ede-new-target ;名称:main;类型:程序。当出现提示时,我将 main.cpp 添加到此目标。
    • 我对其他两个目标(具有 Utils.cpp 和 Utils.h 的 Utils 以及具有 CGrabBuffer.cpp 和 CGrabBuffer.h 的 CGrabBuffer)重复相同的操作。在这里我发现了第一个问题。这两个目标必须是什么类型?我只希望他们生成 .o 文件。
  • 完成此操作后,我向所有三个目标输入 Mx ede-customize-current-target 并添加一些包含路径、一些库等。
  • 在此之后,如果我调用 Mx ede- compile-project 它无法编译,因为:
    • 它首先尝试编译main.cpp;我不知道如何在尝试构建 main.cpp 之前指定(使用 EDE)需要 Utils.o 和 CGrabBuffer.o。
    • 如果我手动更改顺序(编辑 Makefile),则无法链接 main.cpp,因为它找不到 Utils.o 和 CGrabBuffer.o。

正如你所看到的,我正处于一片混乱之中。也许我什至不明白 EDE 中“目标”的含义。我还了解了 ede-cpp-root-project 的存在,该项目必须在 .emacs 文件中指定。我还没有尝试过,因为我认为它所做的只是帮助语义。它不会生成 Makefile,是吗?我可以(或者我是否需要)使用 Project.el 构建的 EDE 项目以及使用 ede-cpp-root-project 进行语义的相同项目?还是多余的?

抱歉,如果我误解了很多事情,但我很困惑,并且对 emacs 不熟悉会让事情变得更糟。感谢您的耐心等待!

编辑:通过一些修改和我收到的回复,我已经能够弄清楚很多东西,所以非常感谢。我仍然不明白的是 ede-cpp-root-project 的使用必须在 .emacs 文件中指定。它只是用于 C++ 语义吗?将项目与 Project.el 一起使用以及 .emacs 中的 elisp 行是否多余?

I have been trying to set up an EDE project for C++ (emacs24 + builtin CEDET) and I'm starting to get desperate because I can't seem to find the way I want the makefiles to be generated. I'm relatively new to Emacs.
I'll try to describe what I'm doing:

I have a toy project set like so:

main.cpp
other/
  Utils.cpp 
  Utils.h
  CGrabBuffer.cpp
  CGrabBuffer.h

main.cpp includes both .h's inside the "other/" directory. These are the steps I follow to set up an EDE project with this simple directory setup:

  • Open main.cpp in emacs and do M-x ede-new ; type: Make ; name: main-proj.
  • Open one of the files in the "other" directory and do M-x ede-new ; type: Make ; name: aux-proj.
  • Now it's time to create the targets (which I believe are three in this case):
    • On the main.cpp buffer: M-x ede-new-target ; name: main ; type: program. When prompted, I add the main.cpp to this target.
    • I repeat the same for the other two targets (Utils which has Utils.cpp and Utils.h and CGrabBuffer which has CGrabBuffer.cpp and CGrabBuffer.h). Here I find the first problem. What type do these two targets have to be? I only want them to generate .o files.
  • Once this is done, I type M-x ede-customize-current-target to all three targets and I add some include paths, some libraries, etc.
  • After this, if I call M-x ede-compile-project it doesn't compile because:
    • It tries to compile main.cpp first; I have no idea how to specify (using EDE) that both Utils.o and CGrabBuffer.o are needed before attempting to build main.cpp.
    • If I manually change the order (editing the Makefile), it's not able to link main.cpp because it can't find Utils.o and CGrabBuffer.o.

As you can see, I am in the middle of a great mess. Maybe I'm not even understanding what "target" means in EDE. I have also read about the existence of ede-cpp-root-project which has to be specified inside the .emacs file. I haven't tried it because what I think it does is just help with the semantics. It doesn't generate Makefiles, does it? Can I have (or do I need) an EDE project built with Project.el's and the same thing using ede-cpp-root-project for the semantics? Or is it redundant?

Sorry If I misunderstood a lot of things but I'm very confused and being new to emacs makes things worse. Thanks for your patience!

EDIT: with some tinkering and the responses I received I have been able to figure out a lot of stuff, so thanks a lot. What I still don't understand is the use of the ede-cpp-root-project which has to be specified inside the .emacs file. Is it just for c++ semantics? Is it redundant to have the project with Project.el's AND also the elisp lines in .emacs?

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

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

发布评论

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

评论(2

鸠书 2025-01-14 10:50:42

EDE 旨在处理许多不同类型的项目,通常是在 Emacs 之外使用其他工具编写构建系统的类型。

为您创建 Makefile 的 EDE 项目类型可以做很多事情,但您需要对构建系统有一些基本的了解才能有所帮助,并且您确实需要自定义项目才能使任何复杂的项目正常工作。

我最近在 EDE 手册中添加了一个部分,以帮助进行自动生成 Automake 文件的基本项目设置。您可以在此处查看教程:

http://www.randomsample.de /cedetdocs/ede/ede/Quick-Start.html

相同的步骤将适用于仅使用 Make 的项目,但由于额外的复杂性,基于 Make 的项目通常会在共享库方面遇到问题。

Mike 的回答非常好,但我认为只需将 .h 文件添加到与 .cpp 源相同的目标即可。它将单独跟踪它们。

另一个有用的技巧是使用整个项目编译按键(Cc . C),每当您更改较大的内容时,它都会使用大写 C。这将重新生成 Makefile,重新运行任何所需的 Automake 功能,并从顶部开始。

编辑:对于给定的项目区域,您只需要一个 EDE 项目。当没有其他自动项目类型工作时,ede-cpp-root 项目非常有用。此时,您可以在 .emacs 文件中创建该文件,以便需要项目定义的其他工具(例如语义的智能完成和标签查找)可以工作。

EDE is designed to handle many different kinds of projects, usually of a type where the build system was written outside of Emacs in some other tool.

The EDE project type that creates Makefiles for you can do quite a few things, but you need to have some basic understanding of build systems for it to be helpful, and you really do need to customize the projects to get anything of any complexity working.

I've recently added a section to the EDE manual to help with basic project setups that autogenerate Automake files. You can check out the tutorial here:

http://www.randomsample.de/cedetdocs/ede/ede/Quick-Start.html

The same steps will apply for projects that just use Make instead, but Make based projects often have trouble with shared libraries due to the extra complexity.

Mike's answer is quite good, but I think it is ok to just add .h files to the same target as your .cpp sources. It will keep track of them separately.

Another useful trick is to use the whole project compile keystroke (C-c . C) which uses a capital C whenever you change something big. That will regenerate the Makefiles, rerun any needed Automake features, and start at the top.

EDIT: You only need one EDE project for a give project area. The ede-cpp-root project is useful when no other automatic project type works. That's when you create that in your .emacs file so that the other tools that need a project definition, like semantic's smart completion, and tag lookup, will work.

感情洁癖 2025-01-14 10:50:42

好吧,我想这次我实际上已经弄清楚了,但它很难看。 Utils.cppCGrabBuffer.cpp 不应该获得它们自己的单独目标,因为似乎没有合适的目标类型。相反,您需要创建一个存档或库,它将自动为您编译 Utils.cppCGrabBuffer.cpp。下面,我假设您想要静态的,但它很容易更改。

[对于任何不熟悉档案或图书馆的人来说,他们基本上只是将 .o 文件收集到一个单独的单元中。它实际上并没有使编译变得更加困难。了解更多此处。]

1) 遵循上面的前两个半步骤(包括创建 main 目标,但不创建其他目标)。

2) 切换到 Utils.cpp 并执行 Mx ede-new-target ;名称: aux ;类型:存档。出现提示时,将 Utils.cpp 添加到此目标。

3) 切换到 CGrabBuffer.cpp 并执行 Cc 操作。一个;目标: aux 。

4) 使用Mx ede-proj-regenerate重新生成Makefile。此时,如果您在 other 子目录中运行 make,您应该会获得存档 libaux.a

5) 切换回 main.cpp 并执行 Mx ede-customize-current-target。这将打开一个交互式 emacs 自定义缓冲区,它允许您编辑 ede 配置的详细信息。在 Ldflags 部分下,单击 [INS]。这会弹出一个新行,上面写着Link Flag:,并且有一些不同颜色的框供您输入(我的是灰色的)。输入-Lother -laux,以便在编译main时包含other/libaux.a。然后,在缓冲区顶部按 [Accept],这将保存该更改并切换回 main.cpp。

6) 使用Mx ede-proj-regenerate重新生成Makefile。

现在,不幸的是,Makefile 首先创建 main 目标,然后下降到 other 目录并创建它。不幸的是,这意味着顶级目录中的 make 无法在干净的树上运行。我不知道为什么会这样,因为在任何使用 EDE 制作的项目中,这似乎都不是您想要的。除了这个 hack 之外,我找不到任何方法来改变它:

7) Do Mxcustomize-project;在推理规则下单击[INS]。然后输入 Target: all ;依赖项: aux main ;规则:[INS];字符串 @: 。 (最后一个只是为了防止带有选项卡的空规则出现错误;可能是 EDE 错误。)单击 [Accept],然后重新生成 Makefile。

所以现在,在你的顶级目录中,你可以运行 make,并且 main 应该是一个工作的可执行文件。

我很快就确信 EDE 还没有准备好供其作者以外的人使用。尽管它的规模很大并且他们显然投入了大量的精力,但它的缺陷太多,太违反直觉,而且不够智能。太可惜了。 Emacs 需要这样的东西。

Well, I think I actually have it figured out this time, but it's ugly. Utils.cpp and CGrabBuffer.cpp should not get their own individual targets, because there doesn't seem to be an appropriate target type. Instead, you'll need to create an archive or library, which will automatically compile Utils.cpp and CGrabBuffer.cpp for you. Below, I'll assume you want static, but it's easy to change.

[For anyone to whom archives or libraries are not familiar, they basically just gather up .o files into a separate unit. It doesn't actually make the compilation harder. Read more here.]

1) Follow the first two and a half steps above (including making the main target, but not the other targets).

2) Switch to Utils.cpp and do M-x ede-new-target ; name: aux ; type: archive. When prompted, add Utils.cpp to this target.

3) Switch to CGrabBuffer.cpp and do C-c . a ; Target: aux .

4) Regenerate the Makefile with M-x ede-proj-regenerate. At this point, if you run make in the other subdirectory, you should get the archive libaux.a.

5) Switch back to main.cpp and do M-x ede-customize-current-target. This brings up an interactive emacs customization buffer, which allows you to edit details of the ede configuration. Under the Ldflags section, click [INS]. This pops out a new line that says Link Flag: and has some different-colored box for you to type in (mine is grey). Type -Lother -laux, so that other/libaux.a is included when compiling main. Then, at the top of the buffer, press [Accept], which should save that change and switch back to main.cpp.

6) Regenerate the Makefile with M-x ede-proj-regenerate.

Now, unfortunately, the Makefile makes the main target first, then descends into the other directory and makes that. Unfortunately, this means that a make from the top-level directory will not work on a clean tree. I don't know why this is, because it seems like that would never be what you want in any project that is ever made with EDE. I can't find any way to change that, except for this hack:

7) Do M-x customize-project; under Inference-Rules click [INS]. Then enter Target: all ; Dependencies: aux main ; Rules: [INS] ; String @: . (This last one is just to prevent an error on an empty rule with a tab; presumably an EDE bug.) Click [Accept], and regenerate the Makefiles.

So now, in your top directory, you can just run make, and main should be a working executable.

I'm quickly becoming convinced that EDE is not yet ready to be used by people other than its authors. Despite its size and the amount of effort they've clearly put into it, it is too buggy, too counterintuitive, and just not smart enough. That's a shame. Emacs needs something like this.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文