mkdir llvm_ninja && cd llvm_ninja
cmake -S ../LLVM/llvm -B build -G Ninja -DLLVM_ENABLE_PROJECTS="compiler-rt;clang-tools-extra;clang;" -DCMAKE_INSTALL_PREFIX=../llvm_release -DCMAKE_BUILD_TYPE=release
cd build
ninja && ninja install
编译报错:
找到相应文件,使用vscode将其用编码utf-8 bom保存即可,有三个文件。
visual studio
makir build
cd build
cmake -DLLVM_ENABLE_PROJECTS="compiler-rt;clang-tools-extra;clang;" -G "Visual Studio 17 2022" -A x64 -Thost=x64 -DCMAKE_BUILD_TYPE=release ..\llvm\LLVM\llvm
放置build
cmake -G Ninja -DLLVM_ENABLE_PROJECTS="compiler-rt;clang-tools-extra;clang;" -DCMAKE_BUILD_TYPE=Debug ../LLVM/llvm
cmake_minimum_required(VERSION 3.4.3)
project(compiler)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_BUILD_TYPE Debug)
list(APPEND CMAKE_PREFIX_PATH "C:/Users/hp/Desktop/files/llvm/llvm_debug/lib/cmake/llvm")
find_package(LLVM REQUIRED CONFIG)
message(STATUS "Found LLVM ${LLVM_PACKAGE_VERSION}")
message(STATUS "Using LLVMConfig.cmake in: ${LLVM_DIR}")
execute_process(COMMAND llvm-config --components OUTPUT_VARIABLE cmps)
message(STATUS "components in: ${cmps}")
include_directories(${LLVM_INCLUDE_DIRS})
include_directories(${PROJECT_SOURCE_DIR}/include)
add_definitions(${LLVM_DEFINITIONS})
aux_source_directory(${PROJECT_SOURCE_DIR}/src src)
# Now build our tools
add_executable(main ${src})
string(STRIP ${cmps} out_cmps)
#llvm_map_components_to_libnames(llvm_libs ${out_cmps})
llvm_map_components_to_libnames(llvm_libs support Core ExecutionEngine Object OrcJIT TargetParser native)
# Link against LLVM libraries
target_link_libraries(main ${llvm_libs})
windows nmake
LLVM_CONFIG = llvm-config
LLVM_LIBS=C:\Users\hp\Desktop\files\llvm\llvm_debug\lib\LLVMWindowsManifest.lib C:\Users\hp\Desktop\files\llvm\llvm_debug\lib\LLVMXRay.lib C:\Users\hp\Desktop\files\llvm\llvm_debug\lib\LLVMLibDriver.lib C:\Users\hp\Desktop\files\llvm\llvm_debug\lib\LLVMDlltoolDriver.lib C:\Users\hp\Desktop\files\llvm\llvm_debug\lib\LLVMCoverage.lib C:\Users\hp\Desktop\files\llvm\llvm_debug\lib\LLVMLineEditor.lib C:\Users\hp\Desktop\files\llvm\llvm_debug\lib\LLVMXCoreDisassembler.lib C:\Users\hp\Desktop\files\llvm\llvm_debug\lib\LLVMXCoreCodeGen.lib C:\Users\hp\Desktop\files\llvm\llvm_debug\lib\LLVMXCoreDesc.lib C:\Users\hp\Desktop\files\llvm\llvm_debug\lib\LLVMXCoreInfo.lib C:\Users\hp\Desktop\files\llvm\llvm_debug\lib\LLVMX86TargetMCA.lib C:\Users\hp\Desktop\files\llvm\llvm_debug\lib\LLVMX86Disassembler.lib C:\Users\hp\Desktop\files\llvm\llvm_debug\lib\LLVMX86AsmParser.lib C:\Users\hp\Desktop\files\llvm\llvm_debug\lib\LLVMX86CodeGen.lib C:\Users\hp\Desktop\files\llvm\llvm_debug\lib\LLVMX86Desc.lib C:\Users\hp\Desktop\files\llvm\llvm_debug\lib\LLVMX86Info.lib C:\Users\hp\Desktop\files\llvm\llvm_debug\lib\LLVMWebAssemblyDisassembler.lib C:\Users\hp\Desktop\files\llvm\llvm_debug\lib\LLVMWebAssemblyAsmParser.lib C:\Users\hp\Desktop\files\llvm\llvm_debug\lib\LLVMWebAssemblyCodeGen.lib C:\Users\hp\Desktop\files\llvm\llvm_debug\lib\LLVMWebAssemblyUtils.lib C:\Users\hp\Desktop\files\llvm\llvm_debug\lib\LLVMWebAssemblyDesc.lib C:\Users\hp\Desktop\files\llvm\llvm_debug\lib\LLVMWebAssemblyInfo.lib C:\Users\hp\Desktop\files\llvm\llvm_debug\lib\LLVMVEDisassembler.lib C:\Users\hp\Desktop\files\llvm\llvm_debug\lib\LLVMVEAsmParser.lib C:\Users\hp\Desktop\files\llvm\llvm_debug\lib\LLVMVECodeGen.lib C:\Users\hp\Desktop\files\llvm\llvm_debug\lib\LLVMVEDesc.lib C:\Users\hp\Desktop\files\llvm\llvm_debug\lib\LLVMVEInfo.lib C:\Users\hp\Desktop\files\llvm\llvm_debug\lib\LLVMSystemZDisassembler.lib C:\Users\hp\Desktop\files\llvm\llvm_debug\lib\LLVMSystemZAsmParser.lib C:\Users\hp\Desktop\files\llvm\llvm_debug\lib\LLVMSystemZCodeGen.lib C:\Users\hp\Desktop\files\llvm\llvm_debug\lib\LLVMSystemZDesc.lib C:\Users\hp\Desktop\files\llvm\llvm_debug\lib\LLVMSystemZInfo.lib C:\Users\hp\Desktop\files\llvm\llvm_debug\lib\LLVMSparcDisassembler.lib C:\Users\hp\Desktop\files\llvm\llvm_debug\lib\LLVMSparcAsmParser.lib C:\Users\hp\Desktop\files\llvm\llvm_debug\lib\LLVMSparcCodeGen.lib C:\Users\hp\Desktop\files\llvm\llvm_debug\lib\LLVMSparcDesc.lib C:\Users\hp\Desktop\files\llvm\llvm_debug\lib\LLVMSparcInfo.lib C:\Users\hp\Desktop\files\llvm\llvm_debug\lib\LLVMRISCVTargetMCA.lib C:\Users\hp\Desktop\files\llvm\llvm_debug\lib\LLVMRISCVDisassembler.lib C:\Users\hp\Desktop\files\llvm\llvm_debug\lib\LLVMRISCVAsmParser.lib C:\Users\hp\Desktop\files\llvm\llvm_debug\lib\LLVMRISCVCodeGen.lib C:\Users\hp\Desktop\files\llvm\llvm_debug\lib\LLVMRISCVDesc.lib C:\Users\hp\Desktop\files\llvm\llvm_debug\lib\LLVMRISCVInfo.lib C:\Users\hp\Desktop\files\llvm\llvm_debug\lib\LLVMPowerPCDisassembler.lib C:\Users\hp\Desktop\files\llvm\llvm_debug\lib\LLVMPowerPCAsmParser.lib C:\Users\hp\Desktop\files\llvm\llvm_debug\lib\LLVMPowerPCCodeGen.lib C:\Users\hp\Desktop\files\llvm\llvm_debug\lib\LLVMPowerPCDesc.lib C:\Users\hp\Desktop\files\llvm\llvm_debug\lib\LLVMPowerPCInfo.lib C:\Users\hp\Desktop\files\llvm\llvm_debug\lib\LLVMNVPTXCodeGen.lib C:\Users\hp\Desktop\files\llvm\llvm_debug\lib\LLVMNVPTXDesc.lib C:\Users\hp\Desktop\files\llvm\llvm_debug\lib\LLVMNVPTXInfo.lib C:\Users\hp\Desktop\files\llvm\llvm_debug\lib\LLVMMSP430Disassembler.lib C:\Users\hp\Desktop\files\llvm\llvm_debug\lib\LLVMMSP430AsmParser.lib C:\Users\hp\Desktop\files\llvm\llvm_debug\lib\LLVMMSP430CodeGen.lib C:\Users\hp\Desktop\files\llvm\llvm_debug\lib\LLVMMSP430Desc.lib C:\Users\hp\Desktop\files\llvm\llvm_debug\lib\LLVMMSP430Info.lib C:\Users\hp\Desktop\files\llvm\llvm_debug\lib\LLVMMipsDisassembler.lib C:\Users\hp\Desktop\files\llvm\llvm_debug\lib\LLVMMipsAsmParser.lib C:\Users\hp\Desktop\files\llvm\llvm_debug\lib\LLVMMipsCodeGen.lib C:\Users\hp\Desktop\files\llvm\llvm_debug\lib\LLVMMipsDesc.lib C:\Users\hp\Desktop\files\llvm\llvm_debug\lib\LLVMMipsInfo.lib C:\Users\hp\Desktop\files\llvm\llvm_debug\lib\LLVMLoongArchDisassembler.lib C:\Users\hp\Desktop\files\llvm\llvm_debug\lib\LLVMLoongArchAsmParser.lib C:\Users\hp\Desktop\files\llvm\llvm_debug\lib\LLVMLoongArchCodeGen.lib C:\Users\hp\Desktop\files\llvm\llvm_debug\lib\LLVMLoongArchDesc.lib C:\Users\hp\Desktop\files\llvm\llvm_debug\lib\LLVMLoongArchInfo.lib C:\Users\hp\Desktop\files\llvm\llvm_debug\lib\LLVMLanaiDisassembler.lib C:\Users\hp\Desktop\files\llvm\llvm_debug\lib\LLVMLanaiCodeGen.lib C:\Users\hp\Desktop\files\llvm\llvm_debug\lib\LLVMLanaiAsmParser.lib C:\Users\hp\Desktop\files\llvm\llvm_debug\lib\LLVMLanaiDesc.lib C:\Users\hp\Desktop\files\llvm\llvm_debug\lib\LLVMLanaiInfo.lib C:\Users\hp\Desktop\files\llvm\llvm_debug\lib\LLVMHexagonDisassembler.lib C:\Users\hp\Desktop\files\llvm\llvm_debug\lib\LLVMHexagonCodeGen.lib C:\Users\hp\Desktop\files\llvm\llvm_debug\lib\LLVMHexagonAsmParser.lib C:\Users\hp\Desktop\files\llvm\llvm_debug\lib\LLVMHexagonDesc.lib C:\Users\hp\Desktop\files\llvm\llvm_debug\lib\LLVMHexagonInfo.lib C:\Users\hp\Desktop\files\llvm\llvm_debug\lib\LLVMBPFDisassembler.lib C:\Users\hp\Desktop\files\llvm\llvm_debug\lib\LLVMBPFAsmParser.lib C:\Users\hp\Desktop\files\llvm\llvm_debug\lib\LLVMBPFCodeGen.lib C:\Users\hp\Desktop\files\llvm\llvm_debug\lib\LLVMBPFDesc.lib C:\Users\hp\Desktop\files\llvm\llvm_debug\lib\LLVMBPFInfo.lib C:\Users\hp\Desktop\files\llvm\llvm_debug\lib\LLVMAVRDisassembler.lib C:\Users\hp\Desktop\files\llvm\llvm_debug\lib\LLVMAVRAsmParser.lib C:\Users\hp\Desktop\files\llvm\llvm_debug\lib\LLVMAVRCodeGen.lib C:\Users\hp\Desktop\files\llvm\llvm_debug\lib\LLVMAVRDesc.lib C:\Users\hp\Desktop\files\llvm\llvm_debug\lib\LLVMAVRInfo.lib C:\Users\hp\Desktop\files\llvm\llvm_debug\lib\LLVMARMDisassembler.lib C:\Users\hp\Desktop\files\llvm\llvm_debug\lib\LLVMARMAsmParser.lib C:\Users\hp\Desktop\files\llvm\llvm_debug\lib\LLVMARMCodeGen.lib C:\Users\hp\Desktop\files\llvm\llvm_debug\lib\LLVMARMDesc.lib C:\Users\hp\Desktop\files\llvm\llvm_debug\lib\LLVMARMUtils.lib C:\Users\hp\Desktop\files\llvm\llvm_debug\lib\LLVMARMInfo.lib C:\Users\hp\Desktop\files\llvm\llvm_debug\lib\LLVMAMDGPUTargetMCA.lib C:\Users\hp\Desktop\files\llvm\llvm_debug\lib\LLVMAMDGPUDisassembler.lib C:\Users\hp\Desktop\files\llvm\llvm_debug\lib\LLVMAMDGPUAsmParser.lib C:\Users\hp\Desktop\files\llvm\llvm_debug\lib\LLVMAMDGPUCodeGen.lib C:\Users\hp\Desktop\files\llvm\llvm_debug\lib\LLVMAMDGPUDesc.lib C:\Users\hp\Desktop\files\llvm\llvm_debug\lib\LLVMAMDGPUUtils.lib C:\Users\hp\Desktop\files\llvm\llvm_debug\lib\LLVMAMDGPUInfo.lib C:\Users\hp\Desktop\files\llvm\llvm_debug\lib\LLVMAArch64Disassembler.lib C:\Users\hp\Desktop\files\llvm\llvm_debug\lib\LLVMAArch64AsmParser.lib C:\Users\hp\Desktop\files\llvm\llvm_debug\lib\LLVMAArch64CodeGen.lib C:\Users\hp\Desktop\files\llvm\llvm_debug\lib\LLVMAArch64Desc.lib C:\Users\hp\Desktop\files\llvm\llvm_debug\lib\LLVMAArch64Utils.lib C:\Users\hp\Desktop\files\llvm\llvm_debug\lib\LLVMAArch64Info.lib C:\Users\hp\Desktop\files\llvm\llvm_debug\lib\LLVMOrcJIT.lib C:\Users\hp\Desktop\files\llvm\llvm_debug\lib\LLVMWindowsDriver.lib C:\Users\hp\Desktop\files\llvm\llvm_debug\lib\LLVMMCJIT.lib C:\Users\hp\Desktop\files\llvm\llvm_debug\lib\LLVMJITLink.lib C:\Users\hp\Desktop\files\llvm\llvm_debug\lib\LLVMInterpreter.lib C:\Users\hp\Desktop\files\llvm\llvm_debug\lib\LLVMExecutionEngine.lib C:\Users\hp\Desktop\files\llvm\llvm_debug\lib\LLVMRuntimeDyld.lib C:\Users\hp\Desktop\files\llvm\llvm_debug\lib\LLVMOrcTargetProcess.lib C:\Users\hp\Desktop\files\llvm\llvm_debug\lib\LLVMOrcShared.lib C:\Users\hp\Desktop\files\llvm\llvm_debug\lib\LLVMDWP.lib C:\Users\hp\Desktop\files\llvm\llvm_debug\lib\LLVMDebugInfoLogicalView.lib C:\Users\hp\Desktop\files\llvm\llvm_debug\lib\LLVMDebugInfoGSYM.lib C:\Users\hp\Desktop\files\llvm\llvm_debug\lib\LLVMOption.lib C:\Users\hp\Desktop\files\llvm\llvm_debug\lib\LLVMObjectYAML.lib C:\Users\hp\Desktop\files\llvm\llvm_debug\lib\LLVMObjCopy.lib C:\Users\hp\Desktop\files\llvm\llvm_debug\lib\LLVMMCA.lib C:\Users\hp\Desktop\files\llvm\llvm_debug\lib\LLVMMCDisassembler.lib C:\Users\hp\Desktop\files\llvm\llvm_debug\lib\LLVMLTO.lib C:\Users\hp\Desktop\files\llvm\llvm_debug\lib\LLVMPasses.lib C:\Users\hp\Desktop\files\llvm\llvm_debug\lib\LLVMCFGuard.lib C:\Users\hp\Desktop\files\llvm\llvm_debug\lib\LLVMCoroutines.lib C:\Users\hp\Desktop\files\llvm\llvm_debug\lib\LLVMipo.lib C:\Users\hp\Desktop\files\llvm\llvm_debug\lib\LLVMVectorize.lib C:\Users\hp\Desktop\files\llvm\llvm_debug\lib\LLVMLinker.lib C:\Users\hp\Desktop\files\llvm\llvm_debug\lib\LLVMInstrumentation.lib C:\Users\hp\Desktop\files\llvm\llvm_debug\lib\LLVMFrontendOpenMP.lib C:\Users\hp\Desktop\files\llvm\llvm_debug\lib\LLVMFrontendOpenACC.lib C:\Users\hp\Desktop\files\llvm\llvm_debug\lib\LLVMFrontendHLSL.lib C:\Users\hp\Desktop\files\llvm\llvm_debug\lib\LLVMExtensions.lib C:\Users\hp\Desktop\files\llvm\llvm_debug\lib\LLVMDWARFLinkerParallel.lib C:\Users\hp\Desktop\files\llvm\llvm_debug\lib\LLVMDWARFLinker.lib C:\Users\hp\Desktop\files\llvm\llvm_debug\lib\LLVMGlobalISel.lib C:\Users\hp\Desktop\files\llvm\llvm_debug\lib\LLVMMIRParser.lib C:\Users\hp\Desktop\files\llvm\llvm_debug\lib\LLVMAsmPrinter.lib C:\Users\hp\Desktop\files\llvm\llvm_debug\lib\LLVMSelectionDAG.lib C:\Users\hp\Desktop\files\llvm\llvm_debug\lib\LLVMCodeGen.lib C:\Users\hp\Desktop\files\llvm\llvm_debug\lib\LLVMObjCARCOpts.lib C:\Users\hp\Desktop\files\llvm\llvm_debug\lib\LLVMIRPrinter.lib C:\Users\hp\Desktop\files\llvm\llvm_debug\lib\LLVMInterfaceStub.lib C:\Users\hp\Desktop\files\llvm\llvm_debug\lib\LLVMFileCheck.lib C:\Users\hp\Desktop\files\llvm\llvm_debug\lib\LLVMFuzzMutate.lib C:\Users\hp\Desktop\files\llvm\llvm_debug\lib\LLVMTarget.lib C:\Users\hp\Desktop\files\llvm\llvm_debug\lib\LLVMScalarOpts.lib C:\Users\hp\Desktop\files\llvm\llvm_debug\lib\LLVMInstCombine.lib C:\Users\hp\Desktop\files\llvm\llvm_debug\lib\LLVMAggressiveInstCombine.lib C:\Users\hp\Desktop\files\llvm\llvm_debug\lib\LLVMTransformUtils.lib C:\Users\hp\Desktop\files\llvm\llvm_debug\lib\LLVMBitWriter.lib C:\Users\hp\Desktop\files\llvm\llvm_debug\lib\LLVMAnalysis.lib C:\Users\hp\Desktop\files\llvm\llvm_debug\lib\LLVMProfileData.lib C:\Users\hp\Desktop\files\llvm\llvm_debug\lib\LLVMSymbolize.lib C:\Users\hp\Desktop\files\llvm\llvm_debug\lib\LLVMDebugInfoPDB.lib C:\Users\hp\Desktop\files\llvm\llvm_debug\lib\LLVMDebugInfoMSF.lib C:\Users\hp\Desktop\files\llvm\llvm_debug\lib\LLVMDebugInfoDWARF.lib C:\Users\hp\Desktop\files\llvm\llvm_debug\lib\LLVMObject.lib C:\Users\hp\Desktop\files\llvm\llvm_debug\lib\LLVMTextAPI.lib C:\Users\hp\Desktop\files\llvm\llvm_debug\lib\LLVMMCParser.lib C:\Users\hp\Desktop\files\llvm\llvm_debug\lib\LLVMIRReader.lib C:\Users\hp\Desktop\files\llvm\llvm_debug\lib\LLVMAsmParser.lib C:\Users\hp\Desktop\files\llvm\llvm_debug\lib\LLVMMC.lib C:\Users\hp\Desktop\files\llvm\llvm_debug\lib\LLVMDebugInfoCodeView.lib C:\Users\hp\Desktop\files\llvm\llvm_debug\lib\LLVMBitReader.lib C:\Users\hp\Desktop\files\llvm\llvm_debug\lib\LLVMFuzzerCLI.lib C:\Users\hp\Desktop\files\llvm\llvm_debug\lib\LLVMCore.lib C:\Users\hp\Desktop\files\llvm\llvm_debug\lib\LLVMRemarks.lib C:\Users\hp\Desktop\files\llvm\llvm_debug\lib\LLVMBitstreamReader.lib C:\Users\hp\Desktop\files\llvm\llvm_debug\lib\LLVMBinaryFormat.lib C:\Users\hp\Desktop\files\llvm\llvm_debug\lib\LLVMTargetParser.lib C:\Users\hp\Desktop\files\llvm\llvm_debug\lib\LLVMTableGen.lib C:\Users\hp\Desktop\files\llvm\llvm_debug\lib\LLVMSupport.lib C:\Users\hp\Desktop\files\llvm\llvm_debug\lib\LLVMDemangle.lib
LLVM_COMPILE_FLAG= /EHsc /Zi /MDd -IC:\Users\hp\Desktop\files\llvm\llvm_debug\include -std:c++17 /EHs-c- /GR- -D_GLIBCXX_ASSERTIONS -D_LIBCPP_ENABLE_ASSERTIONS -D_CRT_SECURE_NO_DEPRECATE -D_CRT_SECURE_NO_WARNINGS -D_CRT_NONSTDC_NO_DEPRECATE -D_CRT_NONSTDC_NO_WARNINGS -D_SCL_SECURE_NO_DEPRECATE -D_SCL_SECURE_NO_WARNINGS -DUNICODE -D_UNICODE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS
all:
cl $(LLVM_COMPILE_FLAG) main.cpp $(LLVM_LIBS)