How to use the output of `llvm-config -cxxflags` on Windows?

I’m a beginner of LLVM and I’d like to include some llvm headers in my file, following is main.cc:

#include<llvm/Config/config.h>
int main(){
return 0;
}

In order to find the include file, I use llvm-config -cxxflags to generate cxxflags for clang++:

-IE:\llvm-project-llvmorg-13.0.1\llvm\include -IE:\llvm-project-llvmorg-13.0.1\build-final\include -std:c++14 /EHs-c- /GR-

then I put cxxflags in to clang++ to compile it, error message is following:

> clang++ -IE:\llvm-project-llvmorg-13.0.1\llvm\include -IE:\llvm-project-llvmorg-13.0.1\build-final\include -std:c++14 /EHs-c- /GR- .\main.cc
clang++: error: unknown argument: '-std:c++14'
clang++: error: no such file or directory: '/EHs-c-'
clang++: error: no such file or directory: '/GR-'

Then I try to use -XClang to wrap the error argument, there are still some errors:

clang++ -IE:\llvm-project-llvmorg-13.0.1\llvm\include -IE:\llvm-project-llvmorg-13.0.1\build-final\include -Xclang -std:c++14 -Xclang /EHs-c- -Xclang /GR- .\main.cc
error: unknown argument: '-std:c++14

I know that I can simply use clang++ -IE:\llvm-project-llvmorg-13.0.1\llvm\include -IE:\llvm-project-llvmorg-13.0.1\build-final\include main.cc to compile my file, but I’m wondering is there a right way to merge llvm-config's output into windows command line?

On windows you want to use clang-cl that works more like Microsoft’s compiler and accepts similar args.

I have never used llvm-config on windows - but I bet those flags are accepted by clang-cl.

Thanks! By the way, I found that clang-cl $($(llvm-config --cxxflags).split()) .\main.cc can work for me

1 Like