跟随LLVM教程时使用Clang编译遇llvm-config协作问题
LLVM官方教程第3章节编译问题求解(Windows 10环境)
环境配置
- Windows 10(AMD R5800H)
- Clang 16.0.0
- LLVM 16.0.0
- CMake 3.25.0
- Clang和LLVM均通过GitHub源码、CMake + VS2022编译构建
代码依赖头文件
#include "llvm/ADT/APFloat.h" #include "llvm/ADT/STLExtras.h" #include "llvm/IR/BasicBlock.h" #include "llvm/IR/Constants.h" #include "llvm/IR/DerivedTypes.h" #include "llvm/IR/Function.h" #include "llvm/IR/IRBuilder.h" #include "llvm/IR/LLVMContext.h" #include "llvm/IR/Module.h" #include "llvm/IR/Type.h" #include "llvm/IR/Verifier.h" #include <algorithm> #include <cctype> #include <cstdio> #include <cstdlib> #include <map> #include <memory> #include <string> #include <vector>
编译错误历程
第一次尝试(PowerShell)
执行教程给出的编译命令:
clang++ -g -O3 my-lang.cc `llvm-config --cxxflags --ldflags --system-libs --libs core` -o mylang
返回错误:
clang: error: unsupported option '--cxxflags' clang: error: unsupported option '--ldflags' clang: error: unsupported option '--system-libs' clang: error: unsupported option '--libs' clang: error: no such file or directory: 'llvm-config' clang: error: no such file or directory: 'core -o' clang: error: no such file or directory: 'mylang'
已尝试操作:重新编译安装Clang/LLVM、切换到CMD执行命令,问题依旧。单独执行llvm-config可正常输出参数,但直接用Clang编译代码会提示找不到LLVM头文件。
第二次尝试(改用PowerShell命令替换语法)
修改命令为:
clang++ -g -O3 my-lang.cc $(llvm-config --cxxflags --ldflags --system-libs --libs core) -o mylang
出现新错误:提示找不到已存在的LLVM库文件,以及psapi.lib等系统库,不清楚这些库的作用及位置。
请求帮助
求解决该编译问题的具体方法。
内容的提问来源于stack exchange,提问作者NoError
相关产品推荐
相关产品推荐

