Clang Static Analyzer emit AST skipping missing headers and missing type definitions

I’m trying to run Clang-16 in Ubuntu 20 for Windows source. I have a limitation of running clang in native development machine. I have to generate AST in linux to be analysed by Clang Static Analyzer link.

hello.cpp

#include <stdio.h>
#include <windows.h>                            // ---> PROBLEM 1 HERE
DumpCreator* DumpCreator::m_MyObj = NULL;       // ---> PROBLEM 2 HERE

int main() {
    printf("Hello World");
}

Command

clang -c -x c++ hello.cpp -emit-ast -D__clang_analyzer__ -w -o hello.ast

Output

hello.cpp:2:10: fatal error: 'windows.h' file not found
#include <windows.h>                            // ---> PROBLEM 1 HERE

Output When Line 2 is Commented

hello.cpp:3:1: error: unknown type name 'DumpCreator'
DumpCreator* DumpCreator::m_MyObj = NULL;       // ---> PROBLEM 2 HERE
^
hello.cpp:3:14: error: use of undeclared identifier 'DumpCreator'
DumpCreator* DumpCreator::m_MyObj = NULL;       // ---> PROBLEM 2 HERE
             ^
2 errors generated.

The Problematic line is <windows.h> inclusion, as it is unavailable in linux environment. I need to tell Clang compiler to skip for missing headers and proceed. Also, when type is unknown clang throws error. Is it possible to tell clang to skip missing headers, type and emit ast.

Can anyone suggest a solution in clang to emit AST skipping errors.

One does not simply “skip compilation errors”. Errors are errors for a reason. The compiler isn’t required to understand your code if there are errors in it, and most of the time it actually doesn’t.

I also don’t think you ever need to use -emit-ast manually. You can invoke the static analyzer on sources just fine.

The traditional solution to your problem is cross-compilation. You cross-compile for Windows on Linux, then you run static analysis on top of that.

I meant to do cross-compilation. But i need the have only the AST of the source. I have a limitation of supplying all necessary headers to the clang.

Invoking Static Analyzer on Sources? Can you please explain a bit more?