首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >在第一次编译时自动停止Visual C++ 2008生成错误?

在第一次编译时自动停止Visual C++ 2008生成错误?
EN

Stack Overflow用户
提问于 2008-09-25 17:44:38
回答 6查看 19.3K关注 0票数 47

我知道我可以编译单个源文件,但有时--比方说,在编辑许多.cpp文件使用的头文件时--需要重新编译多个源文件。这就是构建的目的。

在VC9 (Visual C++ 2008)中,"Build“命令的默认行为是尝试编译所有需要它的文件。有时,这只会导致许多编译失败。我通常只是观察错误,然后按ctrl-break手动停止构建。

有没有办法配置它,使构建在第一次编译错误(而不是第一次失败的项目构建)时自动停止?

EN

回答 6

Stack Overflow用户

回答已采纳

发布于 2009-07-06 03:03:53

我想出了一个更好的宏观家伙。它在出现第一个错误后立即停止(构建窗口更新后立即停止)。

Visual Studio ->工具->宏->宏集成开发环境...(或ALT+F11)

Private Sub OutputWindowEvents_OnPaneUpdated(ByVal pPane As OutputWindowPane) Handles OutputWindowEvents.PaneUpdated
    If Not (pPane.Name = "Build") Then Exit Sub

    pPane.TextDocument.Selection.SelectAll()
    Dim Context As String = pPane.TextDocument.Selection.Text
    pPane.TextDocument.Selection.EndOfDocument()

    Dim found As Integer = Context.IndexOf(": error ")

    If found > 0 Then
        DTE.ExecuteCommand("Build.Cancel")
    End If

End Sub 

希望你们能行得通。

票数 28
EN

Stack Overflow用户

发布于 2008-10-11 22:30:57

这可以通过添加为响应event OnBuildProjConfigDone而运行的宏来完成。

宏如下所示:

Private Sub BuildEvents_OnBuildProjConfigDone(ByVal Project As String, ByVal ProjectConfig As String, ByVal Platform As String, ByVal SolutionConfig As String, ByVal Success As Boolean) Handles BuildEvents.OnBuildProjConfigDone

  If Success = False Then
    DTE.ExecuteCommand("Build.Cancel")
  End If

End Sub
票数 17
EN

Stack Overflow用户

发布于 2011-01-21 18:20:39

是的,这在MSVC 2005-2010上运行得很好:

Public Module EnvironmentEvents
  Private Sub OutputWindowEvents_OnPaneUpdated(ByVal pPane As OutputWindowPane) Handles OutputWindowEvents.PaneUpdated
    If Not (pPane.Name = "Build") Then Exit Sub

    Dim foundError As Boolean = pPane.TextDocument.StartPoint.CreateEditPoint().FindPattern(": error")
    Dim foundFatal As Boolean = pPane.TextDocument.StartPoint.CreateEditPoint().FindPattern(": fatal error")

    If foundError Or foundFatal Then
      DTE.ExecuteCommand("Build.Cancel")
    End If
  End Sub
End Module
票数 8
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/134796

复制
相关文章

相似问题

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