You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

编译LLVM Kaleidoscope教程第8章遇llvm::Function等编译错误求助

解决LLVM Kaleidoscope第8章编译错误的方法

错误1:llvm::Function无insert成员

你的编译环境使用的是LLVM 14,但Function::insert是LLVM 15及以上版本才新增的接口,LLVM 14并不支持。你在Function.h中找到的方法属于新版本LLVM的定义,实际编译时链接的是LLVM 14的库,因此报错。

解决方法:将Function::insert调用替换为LLVM 14支持的BasicBlock::insertInto方法:

  • 原代码:
    TheFunction->insert(TheFunction->end(), ElseBB);
    
    修改为:
    ElseBB->insertInto(TheFunction, TheFunction->end());
    
  • 另一处报错代码同理修改:
    TheFunction->insert(TheFunction->end(), MergeBB);
    
    修改为:
    MergeBB->insertInto(TheFunction, TheFunction->end());
    

错误2:std::optional未定义

LLVM 14的适配代码中,默认使用自身实现的llvm::Optional模板,而非C17标准库的std::optional。报错原因是代码中使用了std::optional,但编译环境未启用C17,或LLVM 14不兼容直接调用标准库版本。

解决方法二选一:

  1. 替换为LLVM自带的Optional:
    auto RM = llvm::Optional<Reloc::Model>();
    
  2. 编译时添加C++17标准支持参数,更新编译命令:
    clang -g -O3 -std=c++17 toy.cpp `llvm-config --cxxflags --ldflags --system-libs --libs all` -o toy
    

内容的提问来源于stack exchange,提问作者rd142857

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.23 14:30:07