How to configure Clang to use MinGW libstdc ++

I am trying to configure Clang on Windows. So far I have survived the construction of Visual Studio and CMake and a few more surprises. But it turns out that Clang does not have its own C ++ implementation of stdlib, so I decided to use GCC 4.7.0 libstdC ++, created for MinGW.

To begin with, I added a search path to my HeaderSearchOptions settings.

headeropts->AddPath(path, clang::frontend::IncludeDirGroup::CXXSystem, true, false, false); 

The path in the place where the headers are stored, I literally copied and pasted it from Windows Explorer (and then doubled the backslash for the screens). But Klang still insists that he cannot find <iostream> , although a file named iostream exists exactly in path .

Why can't Clang find my header and what else do I need to do to use libstdc ++?

Here is my code

 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); 
+8
c ++ clang
source share
1 answer

When using Frontend, you must manually call clang::InitializePreprocessor and clang::BuiltinContext::InitializeBuiltins .

In addition, the trio should call "MinGW32" as a supplier. If you call, say, β€œMinGW”, then Clang will silently understand what you want to say about compatibility and create useless object files.

+4
source share

All Articles