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

WSL下CMake查找LLVM 15报错:LibEdit::LibEdit未找到如何解决?

问题:WSL中LLVM 15 CMake配置报错LibEdit::LibEdit未找到

在WSL(宿主系统为Windows)中搭建基于LLVM IR API的小型CMake项目,已安装llvm-15包,但执行find_package(LLVM 15 REQUIRED CONFIG)时出现错误,提示目标LLVMLineEditor的链接接口依赖LibEdit::LibEdit,但该目标未找到。尝试安装libedit、手动引入该库、重装llvm-15均未解决问题,目前临时改用LLVM 12,寻求彻底解决方案。

具体报错信息:

C:\Windows\system32\wsl.exe --distribution Ubuntu --exec /bin/bash -c "export CMAKE_COLOR_DIAGNOSTICS=ON && export CLION_IDE=TRUE && export JETBRAINS_IDE=TRUE && cd /mnt/d/git/llvm-antlr4-starter/cmake-build-debug-wsl && /usr/bin/cmake -DCMAKE_BUILD_TYPE=Debug -G 'CodeBlocks - Unix Makefiles' -S /mnt/d/git/llvm-antlr4-starter -B /mnt/d/git/llvm-antlr4-starter/cmake-build-debug-wsl"
-- Found LLVM 15.0.6
-- Using LLVMConfig.cmake in: /usr/lib/llvm-15/cmake
CMake Warning (dev) at /usr/share/cmake-3.25/Modules/ExternalProject.cmake:2255 (message):
  Policy CMP0114 is not set: ExternalProject step targets fully adopt their
  steps.  Run "cmake --help-policy CMP0114" for policy details.  Use the
  cmake_policy command to set the policy and suppress this warning.

  ExternalProject target 'antlr4_runtime' would depend on the targets for
  step(s) 'build_static' under policy CMP0114, but this is being left out for
  compatibility since the policy is not set.
Call Stack (most recent call first):
  CMakeLists.txt:149 (ExternalProject_Add_StepTargets)
This warning is for project developers.  Use -Wno-dev to suppress it.

CMake Warning (dev) at /usr/share/cmake-3.25/Modules/ExternalProject.cmake:2255 (message):
  Policy CMP0114 is not set: ExternalProject step targets fully adopt their
  steps.  Run "cmake --help-policy CMP0114" for policy details.  Use the
  cmake_policy command to set the policy and suppress this warning.

  ExternalProject target 'antlr4_runtime' would depend on the targets for
  step(s) 'build_shared' under policy CMP0114, but this is being left out for
  compatibility since the policy is not set.
Call Stack (most recent call first):
  CMakeLists.txt:166 (ExternalProject_Add_StepTargets)
This warning is for project developers.  Use -Wno-dev to suppress it.

LLVM_INCLUDE_DIRS: /usr/lib/llvm-15/include
-- Configuring done
CMake Error at /usr/lib/llvm-15/lib/cmake/llvm/LLVMExports.cmake:1198 (set_target_properties):
  The link interface of target "LLVMLineEditor" contains:

    LibEdit::LibEdit

  but the target was not found.  Possible reasons include:

    * There is a typo in the target name.
    * A find_package call is missing for an IMPORTED target.
    * An ALIAS target is missing.

Call Stack (most recent call first):
  /usr/lib/llvm-15/cmake/LLVMConfig.cmake:336 (include)
  CMakeLists.txt:7 (find_package)


-- Generating done
CMake Generate step failed.  Build files cannot be regenerated correctly.

[Finished]

解决方案

  • 安装libedit开发包
    仅安装libedit包不足以提供CMake所需的配置文件和头文件,需安装开发包:

    sudo apt update && sudo apt install libedit-dev
    
  • 提前引入LibEdit的CMake配置
    在find_package(LLVM 15 REQUIRED CONFIG)之前,向CMakeLists.txt中添加以下代码,确保CMake先识别LibEdit::LibEdit目标:

    find_package(LibEdit REQUIRED)
    
  • 手动指定LibEdit路径(若上述步骤无效)
    如果系统中libedit的安装路径特殊,可通过LibEdit_ROOT变量指定位置:

    • 命令行方式:
      cmake .. -DCMAKE_BUILD_TYPE=Debug -DLibEdit_ROOT=/usr/lib/x86_64-linux-gnu/
      
    • 或在CMakeLists.txt中添加:
      set(LibEdit_ROOT "/usr/lib/x86_64-linux-gnu/")
      
  • 确保LLVM安装完整
    检查并补全llvm-15的相关依赖包:

    sudo apt install llvm-15 llvm-15-dev llvm-15-tools
    

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.09 00:50:46