Hur komplierar jag ett Microsoft Visual Studio Community projekt med Clang?
Jag brukar använda mig av MSVC när jag kompilerar min C-kod. Men nu är jag behov utav VLA = Variable Length Array, dvs att kunna deklerarera en array så här:
int storlek = 5;
int min_array[storlek] = {0};
Detta går faktiskt i C99 och uppåt, men i C++ är det totalt förbjudet! Detta är en anledning att välja C före C++.
Men hur som helst. Jag måste byta kompilator till Clang då Clang stödjer VLA. Hur kan jag göra detta i Visual Studio Community?
Jag har installerat LLVM
C:\vcpkg>vcpkg install llvm:x64-windows
Computing installation plan...
The following packages will be built and installed:
llvm[clang,compiler-rt,core,default-options,default-targets,disable-assertions,disable-clang-static-analyzer,enable-bindings,enable-terminfo,enable-threads,enable-zlib,lld,target-spirv,target-x86,tools]:x64-windows -> 14.0.6
Detecting compiler hash for triplet x64-windows...
Restored 0 package(s) from C:\Users\dmn\AppData\Local\vcpkg\archives in 1.63 ms. Use --debug to see more details.
Installing 1/1 llvm:x64-windows...
Building llvm[clang,compiler-rt,core,default-options,default-targets,disable-assertions,disable-clang-static-analyzer,enable-bindings,enable-terminfo,enable-threads,enable-zlib,lld,target-spirv,target-x86,tools]:x64-windows...
-- Note: llvm only supports static library linkage. Building static library.
-- Downloading https://github.com/llvm/llvm-project/archive/llvmorg-14.0.6.t... -> llvm-llvm-project-llvmorg-14.0.6.tar.gz...
-- Extracting source C:/vcpkg/downloads/llvm-llvm-project-llvmorg-14.0.6.tar.gz
-- Applying patch 0002-fix-install-paths.patch
-- Applying patch 0004-fix-dr-1734.patch
-- Applying patch 0005-fix-tools-path.patch
-- Applying patch 0007-fix-compiler-rt-install-path.patch
-- Applying patch 0009-fix-tools-install-path.patch
-- Applying patch 0010-fix-libffi.patch
-- Applying patch 0011-fix-install-bolt.patch
-- Using source at C:/vcpkg/buildtrees/llvm/src/org-14.0.6-07c830a6c0.clean
-- Found external ninja('1.10.2').
-- Getting CMake variables for x64-windows
-- Downloading https://www.python.org/ftp/python/3.10.7/python-3.10.7-embed-... -> python-3.10.7-embed-amd64.zip...
-- Configuring x64-windows
-- Building x64-windows-dbg
-- Building x64-windows-rel
-- Installing: C:/vcpkg/packages/llvm_x64-windows/share/clang/copyright
-- Installing: C:/vcpkg/packages/llvm_x64-windows/share/clang/usage
-- Installing: C:/vcpkg/packages/llvm_x64-windows/share/lld/copyright
-- Installing: C:/vcpkg/packages/llvm_x64-windows/share/lld/usage
-- Installing: C:/vcpkg/packages/llvm_x64-windows/share/llvm/copyright
-- Installing: C:/vcpkg/packages/llvm_x64-windows/share/llvm/usage
-- Performing post-build validation
-- Performing post-build validation done
Stored binary cache: "C:\Users\dmn\AppData\Local\vcpkg\archives\8d\8d4439738585093ba8ff62152797f4cb73c8ab05607086a577d33c1cfe25651a.zip"
Elapsed time to handle llvm:x64-windows: 3.18 h
Total install time: 3.182 h
The package llvm provides CMake targets:
find_package(LLVM CONFIG REQUIRED)
list(APPEND CMAKE_MODULE_PATH "${LLVM_CMAKE_DIR}")
include(HandleLLVMOptions)
add_definitions(${LLVM_DEFINITIONS})
target_include_directories(main PRIVATE ${LLVM_INCLUDE_DIRS})
# Find the libraries that correspond to the LLVM components that we wish to use
llvm_map_components_to_libnames(llvm_libs Support Core IRReader ...)
# Link against LLVM libraries
target_link_libraries(main PRIVATE ${llvm_libs})
C:\vcpkg>
Edit:
Jag löste detta problem igenom att sätta "Use Vcpkg: No"
Men nu är jag ju utan VCPKG! Jag har behov utav det också.