1

假设我正在构建一个相当大的代码库

我在一个命令中使用 Visual c++ 编译器中的一大堆编译器标志编译一大堆文件,如下所示:

CL.exe /c /I..\..\JuceLibraryCode /I..\..\JuceLibraryCode\modules /ZI /nologo /W4 /WX- /MP1 /Od /Oy- /D WIN32 /D _WINDOWS /D DEBUG /D _DEBUG /D JUCE_UNIT_TESTS=1 /D JUCER_VS2014_78A5021=1 /D JUCE_APP_VERSION=3.0.0 /D JUCE_APP_VERSION_HEX=0x30000 /D _MBCS /Gm- /EHsc /MTd /GS /fp:precise /Zc:wchar_t /Zc:forScope /GR /Fo"Debug\\" /Fd"Debug\\vc140.pdb" /Gd /TP /analyze- /errorReport:prompt ..\..\Source\Main.cpp ..\..\Source\MainWindow.cpp ..\..\Source\IntroScreen.cpp ..\..\Source\Demos\AnimationDemo.cpp ..\..\Source\Demos\AudioLatencyDemo.cpp ..\..\Source\Demos\AudioPlaybackDemo.cpp ..\..\Source\Demos\AudioRecordingDemo.cpp ..\..\Source\Demos\AudioSettingsDemo.cpp ..\..\Source\Demos\AudioSynthesiserDemo.cpp ..\..\Source\Demos\Box2DDemo.cpp ..\..\Source\Demos\CameraDemo.cpp ..\..\Source\Demos\ChildProcessDemo.cpp ..\..\Source\Demos\CodeEditorDemo.cpp ..\..\Source\Demos\ComponentTransformsDemo.cpp ..\..\Source\Demos\CryptographyDemo.cpp ..\..\Source\Demos\DialogsDemo.cpp ..\..\Source\Demos\FontsDemo.cpp ..\..\Source\Demos\GraphicsDemo.cpp ..\..\Source\Demos\ImagesDemo.cpp ..\..\Source\Demos\JavaScript.cpp ..\..\Source\Demos\KeyMappingsDemo.cpp ..\..\Source\Demos\LiveConstantDemo.cpp ..\..\Source\Demos\LookAndFeelDemo.cpp ..\..\Source\Demos\MDIDemo.cpp ..\..\Source\Demos\MidiDemo.cpp ..\..\Source\Demos\MultithreadingDemo.cpp ..\..\Source\Demos\MultiTouch.cpp ..\..\Source\Demos\NetworkingDemo.cpp ..\..\Source\Demos\OpenGLDemo.cpp ..\..\Source\Demos\OpenGLDemo2D.cpp ..\..\Source\Demos\PropertiesDemo.cpp ..\..\Source\Demos\SystemInfoDemo.cpp ..\..\Source\Demos\TimersAndEventsDemo.cpp ..\..\Source\Demos\UnitTestsDemo.cpp ..\..\Source\Demos\ValueTreesDemo.cpp ..\..\Source\Demos\VideoDemo.cpp ..\..\Source\Demos\WebBrowserDemo.cpp ..\..\Source\Demos\WidgetsDemo.cpp ..\..\Source\Demos\WindowsDemo.cpp ..\..\Source\Demos\XMLandJSONDemo.cpp ..\..\JuceLibraryCode\BinaryData.cpp ..\..\JuceLibraryCode\modules\juce_audio_basics\juce_audio_basics.cpp ..\..\JuceLibraryCode\modules\juce_audio_devices\juce_audio_devices.cpp ..\..\JuceLibraryCode\modules\juce_audio_formats\juce_audio_formats.cpp ..\..\JuceLibraryCode\modules\juce_audio_processors\juce_audio_processors.cpp ..\..\JuceLibraryCode\modules\juce_audio_utils\juce_audio_utils.cpp ..\..\JuceLibraryCode\modules\juce_box2d\juce_box2d.cpp ..\..\JuceLibraryCode\modules\juce_core\juce_core.cpp ..\..\JuceLibraryCode\modules\juce_cryptography\juce_cryptography.cpp ..\..\JuceLibraryCode\modules\juce_data_structures\juce_data_structures.cpp ..\..\JuceLibraryCode\modules\juce_events\juce_events.cpp ..\..\JuceLibraryCode\modules\juce_graphics\juce_graphics.cpp ..\..\JuceLibraryCode\modules\juce_gui_basics\juce_gui_basics.cpp ..\..\JuceLibraryCode\modules\juce_gui_extra\juce_gui_extra.cpp ..\..\JuceLibraryCode\modules\juce_opengl\juce_opengl.cpp ..\..\JuceLibraryCode\modules\juce_video\juce_video.cpp

假设我得到一个 ICE,它位于某个源文件(翻译单元)直接或间接包含的头文件中,有没有办法直接或间接追踪哪个翻译单元(源 .cpp 文件)(通过其他一些头)包括发生ICE的头?

我在控制台中获得的输出似乎真的很混乱,以至于我无法通过查看它轻松找出哪个源文件包含具有 ICE 的标头。

4

1 回答 1

0

如果您使用cl /E而不是编译/c,您将获得输出(stdout默认情况下),并在文件首次合并到翻译单元时使用以下符号:

#line 1 "...file [path and] name..."

可以找一下#line 1报ICE的header对应的那一行,然后回看之前#line的s,看看哪些文件直接和间接包含了它。

例子

我下面的评论是内联的,被 [[[三方括号]]] 包围。#line请记住在...之后通过行号“1”来推断源文件是新包含的还是正在“返回”的其他文件。

 ~/dev/tr  cat h.h
#pragma once
h one
h two
h three
 ~/dev/tr  cat i.h
#pragma once
#include "h.h"
 ~/dev/tr  cat tr1.cpp
#include "h.h"
struct X { };
 ~/dev/tr  cat tr2.cpp
#include "i.h"
int main()
{
    X x;
}
 ~/dev/tr  cl /E tr1.cpp tr2.cpp
Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 15.00.30729.01 for 80x86
Copyright (C) Microsoft Corporation.  All rights reserved.

tr1.cpp
#line 1 "tr1.cpp"
#line 1 "c:\\home\\anthony\\user\\dev\\tr\\h.h"
        [[[ above line means prior context of tr1.cpp has #included h.h ]]]
#pragma once
h one
h two
h three
#line 2 "tr1.cpp"
        [[[ above line means prior context of h.h "popped", returning to
            tr1.cpp at line 2 ]]]
struct X { };
tr2.cpp
#line 1 "tr2.cpp"
#line 1 "c:\\home\\anthony\\user\\dev\\tr\\i.h"
        [[[ i.e. tr2.cpp #included i.h ]]]
#pragma once
#line 1 "c:\\home\\anthony\\user\\dev\\tr\\h.h"
        [[[ i.e. prior context of i.h #included h.h ]]]
#pragma once
h one
h two
h three
#line 3 "c:\\home\\anthony\\user\\dev\\tr\\i.h"
        [[[ i.e. i.h continues after the "include h.h" line ]]]
#line 2 "tr2.cpp"
        [[[ i.e. tr2.cpp continues after the "include i.h" line ]]]
int main()
{
    X x;
}
于 2015-01-22T03:39:42.010 回答