[英]How to set up Clang to use MinGW libstdc++
我一直在尝试在Windows上设置Clang。 到目前为止,我幸免于使用Visual Studio和CMake进行构建,以及其他一些惊喜。 但是事实证明,Clang没有附带自己的C ++ stdlib实现,因此我决定使用为MinGW构建的GCC 4.7.0的libstdc ++。
首先,我将搜索路径添加到HeaderSearchOptions中。
headeropts->AddPath(path, clang::frontend::IncludeDirGroup::CXXSystem, true, false, false);
该路径正是标题所在的位置-我从Windows资源管理器中逐字复制并粘贴了该路径(然后将反斜杠加倍以进行转义)。 但是Clang仍然坚持认为,即使名为iostream
的文件恰好位于path
,也无法找到<iostream>
。
为什么Clang找不到我的标头,使用libstdc ++我还需要做什么?
这是我的代码
llvm::LLVMContext c;
llvm::Module m("", c);
clang::CompilerInstance ci;
clang::FileSystemOptions fso;
clang::FileManager fm(fso);
std::string errors;
llvm::raw_string_ostream error_stream(errors);
clang::DiagnosticOptions diagopts;
clang::TextDiagnosticPrinter printer(error_stream, &diagopts);
llvm::IntrusiveRefCntPtr<clang::DiagnosticIDs> diagids(new clang::DiagnosticIDs);
clang::DiagnosticsEngine engine(diagids, &diagopts, &printer, false);
clang::SourceManager sm(engine, fm);
clang::LangOptions langopts;
langopts.CPlusPlus = true;
langopts.CPlusPlus0x = true;
clang::TargetOptions target;
target.Triple = llvm::sys::getDefaultTargetTriple();
auto targetinfo = clang::TargetInfo::CreateTargetInfo(engine, &target);
auto headeropts = llvm::IntrusiveRefCntPtr<clang::HeaderSearchOptions>(new clang::HeaderSearchOptions());
headeropts->AddPath("D:\\Backups\\unsorted\\x86_64-w64-mingw32-gcc-4.7.0-release-win64_rubenvb\\mingw64\\include\\c++\\4.7.0",clang::frontend::IncludeDirGroup::CXXSystem, true, false, false);
headeropts->UseStandardCXXIncludes = true;
headeropts->UseStandardSystemIncludes = true;
clang::HeaderSearch hs(headeropts, fm, engine, langopts, targetinfo);
auto x = llvm::IntrusiveRefCntPtr<clang::PreprocessorOptions>(new clang::PreprocessorOptions());
clang::Preprocessor p(x, engine, langopts, targetinfo, sm, hs, ci);
clang::ASTContext astcon(langopts, sm, targetinfo, p.getIdentifierTable(), p.getSelectorTable(), p.getBuiltinInfo(), 1000);
CodeGenConsumer consumer;
clang::CodeGen::CodeGenModule codegen(astcon, clang::CodeGenOptions(), m, llvm::DataLayout(&m), engine);
consumer.mod = &codegen;
clang::Sema sema(p, astcon, consumer, clang::TranslationUnitKind::TU_Complete);
sm.createMainFileID(fm.getFile("main.cpp"));
engine.getClient()->BeginSourceFile(langopts, &p);
clang::ParseAST(sema);
不使用前端时,必须手动调用clang::InitializePreprocessor
和clang::BuiltinContext::InitializeBuiltins
。
此外,三元组必须将“ MinGW32”命名为供应商。 如果您说“ MinGW”,那么Clang将无声地无法意识到您希望实现所述兼容性并产生无用的目标文件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.