【问题标题】:How do I add a make target to a build configuration in Eclipse?如何将 make 目标添加到 Eclipse 中的构建配置?
【发布时间】:2011-04-07 06:41:10
【问题描述】:

我已在 Eclipse C++ 项目中将test 目标添加到makefile.targets。现在,我希望将其构建为我的调试和发布构建配置的一部分,这样我就可以让我的单元测试作为正常构建过程的一部分运行。

鉴于我无法编辑自动生成的Debug/makefileRelease/makefile,我该怎么做?

【问题讨论】:

    标签: eclipse makefile eclipse-cdt


    【解决方案1】:

    下面的伪代码有望回答有关目标添加的问题,并另外解决了如何在 makefile 和源代码中使用变量。

    我花了一天的时间使用网络资源来解决这个问题,尤其是 stackoverflow.com 和 eclipse.org 论坛。 CDT 的 Eclipse 文档在某些方面有点含糊。

    // pseudo-code for Eclipse version Kepler
    if ("Project.Properties.C/C++ Build.Generate Makefiles automatically" == true) {
      // when using the automatically generated makefiles,
      //   use the -include's in the generated Debug/makefile
      cp <your makefile init statements> $(ProjDirPath)/makefile.init
      cp <your makefile definitions>     $(ProjDirPath)/makefile.defs
      cp <your makefile targets>         $(ProjDirPath)/makefile.targets
    } else {
      // when using a makefile that you maintain, alter your own makefile
      cp <your makefile targets>         <your makefile>
    }
    // Additionally, you may want to provide variables for use in the makefile 
    //   commands, whether it's your own makefile or the generated one:
    //    Note that:
    //    - "Preferences.C/C++.Build.Build Variables" and
    //      "Project.Properties.C/C++ Build.Build Variables" 
    //       are *NOT directly available* to the makefile commands.
    //    - "Preferences.C/C++.Build.Environment" variables and
    //      "Project.Properties.C/C++ Build.Environment" variables
    //      *ARE available* to the makefile commands.
    //    - To make "Build Variables" available to the makefile and source files,
    //      add an environment variable as shown below. Especially useful are the
    //      built-in ones visible when "Show system variables" is checked.
    
    // assign the build system variable "ProjDirPath" as a *user preference*
    "Preferences.C/C++.Build.Environment".AddKeyValue("ProjDirPath",
                                                      "${ProjDirPath}"}
    
    // assign the build system variable "ProjDirPath" as a *project property*
    "Project.Properties.C/C++ Build.Environment".AddKeyValue("ProjDirPath",
                                                             ${ProjDirPath}")
    

    “makefile.init”示例:

    GREP := /bin/grep
    

    “makefile.defs”示例:

    ifndef ProjDirPath
      $(error "ProjDirPath" undefined as a "make variable" or "environment variable".)
    endif
    

    生成的makefile Debug/src/subdir.mk 将依赖项提取到 文件 ${ProjDirPath}/Debug/src/${ProjName}.d,但您需要添加一个额外的目标来初始生成依赖项。您可以添加一个目标:

    #include "automated_headers.h"
    

    通过将目标添加到 ${ProjDirPath}/makefile.targets。

    “makefile.targets”示例:

    # targets to generate a header file
    %/src/automated_headers.h: %/src/generate_headers.py $(external_library_info)
        @echo "Generating $@"
        %/src/generate_headers.py $(extrnal_library_info) $@
    
    src/$(ProjName).o: $(ProjDirPath)/src/automated_headers.h
    

    【讨论】:

      【解决方案2】:

      如果Make Target 视图尚未打开,请打开它。它有一个New Make Target 按钮。

      或者,在 makefile 中突出显示目标的名称,右键单击,然后转到 Make Targets -&gt; Create...

      编辑:我可能误解了你的问题。如果您希望构建目标,请在单击构建时转到构建首选项并将其添加到那里。

      【讨论】:

      • 好的,我确实想让我添加到makefile.targets 的目标包含在我的构建配置中。我会清理问题并尝试您的建议。 :)
      • Hrm,编辑构建配置对我来说似乎是禁用的,至少从“项目”>“构建配置”菜单 - 管理构建配置是灰色的。有什么建议吗?
      • @Josh:对不起,我自己不使用自动生成的 makefile,所以我无法帮助你。我认为这类似于使用手动 makefile,但不是。
      猜你喜欢
      • 1970-01-01
      • 2012-03-02
      • 1970-01-01
      • 2011-01-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-08-25
      • 2013-06-02
      相关资源
      最近更新 更多