Próbowałem skonfigurować Clang w systemie Windows. Do tej pory przeżyłem budynek z Visual Studio i CMake i kilkoma innymi niespodziankami. Ale okazuje się, że Clang nie ma własnej implementacji stdlib C++, więc zdecydowałem się użyć biblioteki libstdC++ GCC 4.7.0 zbudowanej dla MinGW.Jak ustawić Clang, aby użyć MinGW libstdC++
Na początek dodałem ścieżkę wyszukiwania do mojego HeaderSearchOptions.
headeropts->AddPath(path, clang::frontend::IncludeDirGroup::CXXSystem, true, false, false);
Ścieżka jest dokładnie tam, gdzie nagłówki reside- dosłownie skopiować i wkleić go w Eksploratorze Windows (a następnie podwoił backslashy dla ucieczek). Ale Clang nadal twierdzi, że nie może znaleźć <iostream>
, mimo że plik o nazwie iostream
istnieje dokładnie pod numerem path
.
Dlaczego Clang nie może znaleźć mojego nagłówka i co jeszcze muszę zrobić, aby użyć libstdC++?
Oto mój kod
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);
Prosta opcja '-I' powinna wystarczyć. Uruchom 'gcc -v' i' gcc -E' (na przykładowym wejściu), aby znaleźć wszystkie ścieżki, których używa. –