如何设置Clang使用MinGW libstdc++
How to set up Clang to use MinGW libstdc++
我一直在尝试在Windows上设置Clang。到目前为止,我在Visual Studio和CMake的帮助下幸存了下来,还有一些其他的惊喜。但是Clang没有自己的c++标准库实现,所以我决定使用GCC 4.7.0为MinGW构建的libstdc++。
首先,我将搜索路径添加到我的HeaderSearchOptions中。
headeropts->AddPath(path, clang::frontend::IncludeDirGroup::CXXSystem, true, false, false);
路径正是头文件所在的位置——我从Windows资源管理器复制并粘贴了它(然后将反斜杠加倍用于转义)。但是Clang仍然坚持找不到<iostream>
,即使一个名为iostream
的文件正好存在于path
。
为什么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);
不使用Frontend时需要手动调用clang::InitializePreprocessor
和clang::BuiltinContext::InitializeBuiltins
此外,该三元组必须将"MinGW32"命名为供应商。如果您命名为"MinGW",那么Clang将不会意识到您所希望的兼容性,并生成无用的目标文件。
相关文章:
- Clang bug?使用指针作为模板参数
- 如何使用Clang/GCC在Mac上为C/C++设置VSCode
- C++17 - 使用自定义分配器的节点提取/重新插入 - 适用于 clang++/libc++,但不适用于 libstd
- 使用 Clang++ 有没有办法将文件作为命名空间等包含?
- 错误:使用 clang 没有可行的重载,使用 GCC 编译
- 在Linux上使用Clang / OLLVM交叉编译helloworld Windows可执行文件时的问题
- 如何使用 CLANG 禁用格式安全错误?
- 在项目中使用 clang 作为库C++
- 在 Clang 中使用指向成员的指针时出错
- clang:使用 O3 导出隐式实例化函数的符号
- 防止 clang++ 使用默认包含
- Clang 3.8 C++ - 使用 LibTooling 读取目录中的所有源文件
- Clang 使用 LibTooling Rewriter 生成新文件
- G 越野车吗?还有clang ?G 使用-O0和-O1选项编译了代码,而对于-O0和-O2,Clang
- 如何强制 clang 使用 system(ubuntu) STL 标头而不是 clang 的
- 如何强制 clang 使用 llvm 汇编程序而不是系统
- Clang 使用了错误的系统包含目录
- GCC vs clang -使用' make_overload '可变lambda继承时的模糊重载
- 为什么gcc/clang使用两个128位的xmm寄存器来传递单个值
- 如何设置Clang使用MinGW libstdc++