我在 Windows 上使用 Cmake、Clion、LLVM、CLang 来构建我的项目
我收到以下错误
ninja: error: 'C:/Program Files (x86)/Microsoft Visual Studio/2019/Professional/DIA SDK/lib/amd64/diaguids.lib', needed by 'CheckClang.exe', missing and no known rule to make it
错误似乎很模糊,我什至没有安装 Visual Studio 2019,我安装了 Visual Studio 2022(不在默认路径上),但是我看不到一种方法来告诉我的 Visual Studio 位于此处。
我尝试将生成器选项更改为 VS 17 (2022),但是使用不同的格式却遇到了相同的错误
CMakeLists:
cmake_minimum_required(VERSION 3.27)
project(CheckClang)
set(CMAKE_CXX_STANDARD 17)
# Set the path to your LLVM and Clang installation
set(LLVM_DIR "D:/Software/Installed/llvmclang/lib/cmake/llvm")
set(Clang_DIR "D:/Software/Installed/llvmclang/lib/cmake/clang")
find_package(LLVM REQUIRED CONFIG)
find_package(Clang REQUIRED CONFIG)
message(STATUS "Found LLVM ${LLVM_PACKAGE_VERSION}")
message(STATUS "Using LLVMConfig.cmake in: ${LLVM_DIR}")
# Set your project compile flags.
if (MSVC)
# Set iterator debugging level
add_compile_options(/D_ITERATOR_DEBUG_LEVEL=0) # Change to 0, 1, or 2 as needed
endif ()
# E.g. if using the C++ header files
# you will need to enable C++11 support
# for your compiler.
include_directories(${LLVM_INCLUDE_DIRS})
separate_arguments(LLVM_DEFINITIONS_LIST NATIVE_COMMAND ${LLVM_DEFINITIONS})
add_definitions(${LLVM_DEFINITIONS_LIST})
# Your executable target
add_executable(CheckClang main.cpp)
# Find the libraries that correspond to the LLVM components
# that we wish to use
llvm_map_components_to_libnames(llvm_libs support core irreader)
# Other clang libs clangTooling clangAST clangASTMatchers clangBasic
# Link against LLVM libraries
#LLVMX86AsmParser # MC, MCParser, Support, X86Desc, X86Info
#LLVMX86Desc # MC, Support, X86AsmPrinter, X86Info
#LLVMX86AsmPrinter # MC, Support, X86Utils
#LLVMX86Info # MC, Support, Target
#LLVMX86Utils # Core, Support
#LLVMipo
#LLVMScalarOpts
#LLVMInstCombine
#LLVMTransformUtils
#LLVMipa
#LLVMAnalysis
#LLVMTarget
#LLVMOption # Support
#LLVMMCParser # MC, Support
#LLVMMC # Object, Support
#LLVMObject # BitReader, Core, Support
#LLVMBitReader # Core, Support
#LLVMCore # Support
#LLVMSupport
target_link_libraries(CheckClang ${llvm_libs})
#clangFrontend
#clangSerialization
#clangDriver
#clangParse
#clangSema
#clangAnalysis
#clangAST
#clangBasic
#clangEdit
#clangLex
#clangTooling
target_link_libraries(CheckClang clangTooling)
# These compile options are available /MD /MDd /MT /MTd
# Set the runtime library option for the target
target_compile_options(CheckClang PRIVATE /MD)
我在 VS 2022 Community 中也遇到了完全相同的错误。 不幸的是,这个问题似乎在发布近 9 个月后仍未得到解决。
该问题正在 LLVM GitHub 上进行讨论:https://github.com/llvm/llvm-project/issues/86250,但尽管进行了版本更新,问题仍然存在。
这似乎是一个明显的内部 LLVM 问题,特别与“llvm_map_components_to_libnames”相关。由于目标只是查找并链接静态库,因此无论是否安装了 VS 2019 或者不是。
更准确地说,这可以通过在具有管理权限的 cmd 提示符下执行以下命令来完成:
mkdir "C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\DIA SDK\lib\amd64"
copy /B "%VSINSTALLDIR%\DIA SDK\lib\amd64\diaguids.lib" "C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\DIA SDK\lib\amd64\diaguids.lib"