Reputation: 8262
I am using Cmake, Clion, LLVM, CLang on Windows to build my project
I'm getting the following error
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
The error seems vague, I don't even have Visual Studio 2019 installed, I have Visual Studio 2022 installed (not on a default path), However I can't see a way to tell that my Visual Studio is located here.
I tried changing the generator option to VS 17 (2022), however got the same error with different formatting
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)
Upvotes: 1
Views: 474
Reputation: 5589
I found this while trying to build include-what-you-use. To build that I had to download clang 19.1.0 and encountered the same problem.
I fixed it by hacking C:\clang19\lib\cmake\llvm\LLVMExports.cmake (line 482)
set_target_properties(LLVMDebugInfoPDB PROPERTIES
# This is wrong!
#INTERFACE_LINK_LIBRARIES "C:/Program Files (x86)/Microsoft Visual Studio/2019/Professional/DIA SDK/lib/amd64/diaguids.lib;LLVMBinaryFormat;LLVMObject;LLVMSupport;LLVMDebugInfoCodeView;LLVMDebugInfoMSF"
INTERFACE_LINK_LIBRARIES "C:/Program Files/Microsoft Visual Studio/2022/Professional/DIA SDK/lib/amd64/diaguids.lib;LLVMBinaryFormat;LLVMObject;LLVMSupport;LLVMDebugInfoCodeView;LLVMDebugInfoMSF"
)
Bit of a hacky solution but it may help on non mission critical stuff.
Upvotes: 0
Reputation: 1
I also encountered the exact same error in VS 2022 Community. Unfortunately, it seems that this issue has not been resolved even after almost 9 months since this question was posted.
The problem is being discussed on the LLVM GitHub at https://github.com/llvm/llvm-project/issues/86250, but despite a version update, the issue still persists.
It appears to be a clear internal LLVM issue, specifically related to 'llvm_map_components_to_libnames'. Since the goal is simply to find and link the static library, the issue can be easily worked around by locating diaguids.lib from the current version of VS and copying it to the path where the error occurs, regardless of whether "VS 2019 Professional" is installed or not.
More precisely, this can be done by executing the following command in a cmd prompt with administrative privileges:
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"
=== UPDATED ===
If you are planning to write additional plugins, using the prebuilt LLVM is discouraged due to significant compatibility issues. After bypassing the above error, I found that some LLVM-related libraries were built with the MT_StaticRelease option, making them completely unusable for my purposes, MD_DynamicRelease.
The only viable solution was to rebuild LLVM from source, ensuring all the necessary configurations were correctly set for compatibility.
Upvotes: 0