如何使用 Eclipse CDT 构建 SCons 项目?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1052759/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 13:50:28  来源:igfitidea点击:

How to build SCons projects with Eclipse CDT?

eclipsebuildeclipse-cdtscons

提问by nos

We have a fairly large C/C++ project using scons for the building. I'd like to go at an attempt to build this through Eclipse-CDT. Anyone have any experience with this and can tell me the steps to set up scons as a builder. (NOT using the SConsBuilder plugin, it will not work with the Eclipse-CDT from Fedora-11).

我们有一个相当大的 C/C++ 项目,使用 scons 进行构建。我想尝试通过 Eclipse-CDT 来构建它。任何人都有这方面的经验,并且可以告诉我将 scons 设置为构建器的步骤。(不使用 SConsBuilder 插件,它不适用于 Fedora-11 中的 Eclipse-CDT)。

采纳答案by richq

I've tried Waf in Eclipse CDTbefore now, SCons would be really similar. The solution was to create an empty Makefile project, then simply change "make" to "scons" in the options. On Windows that would probably need the scons.bat file in your path. That is not much better than creating a dummy Makefile that has an all:\n\tsconstype pattern in it, but is the least work.

我之前在 Eclipse CDT 中尝试过Waf,SCons 会非常相似。解决方案是创建一个空的 Makefile 项目,然后只需在选项中将“make”更改为“scons”。在 Windows 上,您的路径中可能需要 scons.bat 文件。这并不比创建一个包含all:\n\tscons类型模式的虚拟 Makefile 好多少,但工作量最少。

The SConsBuilder pluginis not a good idea. It has a whole bunch of hard coded python code in there that it spits out to a SConstruct. It hasn't been updated in ages and a lot of code is probably deprecated in SCons by now. I think a better approach is to do what SCons does for Visual Studio, or what CMake does for Eclipse CDT. That means generating a .cproject file on the fly based on your build configuration.

SConsBuilder插件是不是一个好主意。它有一大堆硬编码的 python 代码,它会向 SConstruct 输出。它已经很久没有更新了,现在 SCons 中的很多代码可能已被弃用。我认为更好的方法是做 SCons 为 Visual Studio 所做的事情,或者 CMake 为 Eclipse CDT 所做的事情。这意味着根据您的构建配置动态生成 .cproject 文件。

I wrote an Eclipse project generator for Wafat one point, which walks the build nodes gathering source files and spits out a .project and .cproject file. Similar to how CMake does it, but Waf's default behaviour of creating a variant directory means you don't have to deal with out-of-source build issues. This has since been added as an extra in waf itself. It uses only part of the Waf API so it would be possible to convert it to SCons with some small-ish amount of work. In other words, there's nothing much out there. The .cproject format is not really documented anywhere and is really ugly compared to the Java version.

我曾经为 Waf编写了一个Eclipse 项目生成器,它遍历构建节点,收集源文件并输出一个 .project 和 .cproject 文件。与 CMake 的做法类似,但 Waf 创建变体目录的默认行为意味着您不必处理源外构建问题。这已经作为额外添加到 waf 本身。它仅使用 Waf API 的一部分,因此可以通过一些少量的工作将其转换为 SCons。换句话说,那里没有什么。.cproject 格式并没有真正记录在任何地方,与 Java 版本相比真的很难看。

I didn't get on too well with CDT though - it is a long way behind the Java dev tools - and I still use Vim with :make, so it was all a bit academic in the end.

不过,我对 CDT 的使用不太好——它远远落后于 Java 开发工具——而且我仍然使用 Vim 和:make,所以最后它有点学术性。

回答by PeterSom

One of our students implemented a new SCons integration for Eclipse CDT that works bi-directional, i.e., it can import SCons files and populate Eclipse CDT projects with the corresponding settings and it can generate SCons files from Eclipse project settings. In addition it provides an interactive SCons mode that speeds up incremental building of larger SCons projects significantly. It will be released to the public for free soon, see http://sconsolidator.com

我们的一个学生为 Eclipse CDT 实现了一个新的 SCons 集成,它可以双向工作,即它可以导入 SCons 文件并使用相应的设置填充 Eclipse CDT 项目,并且它可以从 Eclipse 项目设置生成 SCons 文件。此外,它还提供交互式 SCons 模式,可显着加快更大 SCons 项目的增量构建。即将免费向公众发布,请参阅http://sconsolidator.com

回答by dmeister

You can use a Makefile that simply delegates the important targets to scons

您可以使用 Makefile 将重要目标简单地委托给 scons

.PHONY: all clean install
default:    all
all:    
    scons
clean:
    scons -c
install:
    scons install

Then it is possible to use "Standard Make C Project" out of the box.

然后就可以开箱即用地使用“Standard Make C Project”了。

回答by Torsten

Just change builder settings, no plugins required. Choose external builder and set scons instead of make and set workdir to dir where SConstruct placed.

只需更改构建器设置,无需插件。选择外部构建器并设置 scons 而不是 make 并将 workdir 设置为 SConstruct 放置的目录。

Now, you can use make targets view to create scons build commands and execute it like make commands. Error parsers with scons works fine by default, no additional configuration required.

现在,您可以使用 make 目标视图来创建 scons 构建命令并像 make 命令一样执行它。默认情况下,带有 scons 的错误解析器可以正常工作,不需要额外的配置。

回答by Benjamin

http://sconsolidator.com/Sconsolidator should work though.

http://sconsolidator.com/Sconsolidator 应该可以工作。

回答by davmp

Be VERY VERY careful about using Sconsolidator with an existing project!! It will blindly overwrite any existing SConstruct/SConscript files you have in the root directory of your project when you click the link to add a SCons nature to your project. (I'm trying to report this as a bug to the project, but being blocked at every turn so far.)

在现有项目中使用 Sconsolidator 时要非常小心!!当您单击链接将 SCons 性质添加到您的项目时,它将盲目地覆盖您在项目根目录中的任何现有 SConstruct/SConscript 文件。(我试图将此报告为该项目的错误,但到目前为止每次都被阻止。)