I want to build Clang compiling for STM32 (arm-none-eabi) under x64 Windows 10, then setup VSCode to use this Clang to compile my stm32 firmwares to ARM binaries. I have read LLVM manuals, there is no clear information (or it just doesnt work) how to make an LLVM crosscompiler for ARM under Windows. I run cmake and ninja within Powershell after running the Native x64 devtools vcvarsall.bat, using following configuration for cmake:
cmake -GNinja -DLLVM_ENABLE_PROJECTS=clang -DCMAKE_BUILD_TYPE=Release -DLLVM_TARGETS_TO_BUILD=ARM -DLLVM_TARGET_ARCH=ARM -DLLVM_HOST_TRIPLE="x86_64-pc-windows" -DLLVM_DEFAULT_TARGET_TRIPLE="arm-none-eabi" -DCMAKE_CXX_STANDARD=17 -DLLVM_USE_CRT_DEBUG=MDd -DLLVM_USE_CRT_RELEASE=MD ..\llvm-project\llvm\
And after running "ninja clang" I got this (I think it cant find proper ucrt library build (x64 Release) should be located somewhere in Windows sdk folder, but if I attempt to pass it to cmake, it doesnt change anything):
-- Build files have been written to: C:/Users/iTXS/build_ninja
PS C:\Users\iTXS\build_ninja> ninja clang
[1/1992] Linking CXX executable bin\clang-tblgen.exe
FAILED: bin/clang-tblgen.exe
cmd.exe /C "cd . && C:\PROGRA~1\MIB055~1\2022\COMMUN~1\VC\Tools\Llvm\x64\bin\CLANG_~1.EXE -fuse-ld=lld-link -nostartfiles -nostdlib -Werror=date-time -Werror=unguarded-availability-new -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers -pedantic -Wno-long-long -Wc++98-compat-extra-semi -Wimplicit-fallthrough -Wcovered-switch-default -Wno-noexcept-type -Wnon-virtual-dtor -Wdelete-non-virtual-dtor -Wsuggest-override -Wstring-conversion -Wmisleading-indentation -Wctad-maybe-unsupported -ffunction-sections -fdata-sections -fno-common -Woverloaded-virtual -Wno-nested-anon-types -O3 -DNDEBUG -D_DLL -D_MT -Xclang --dependent-lib=msvcrt -Xlinker /subsystem:console -Wl,--gc-sections tools/clang/utils/TableGen/CMakeFiles/clang-tblgen.dir/ASTTableGen.cpp.obj tools/clang/utils/TableGen/CMakeFiles/clang-tblgen.dir/ClangASTNodesEmitter.cpp.obj tools/clang/utils/TableGen/CMakeFiles/clang-tblgen.dir/ClangASTPropertiesEmitter.cpp.obj tools/clang/utils/TableGen/CMakeFiles/clang-tblgen.dir/ClangAttrEmitter.cpp.obj tools/clang/utils/TableGen/CMakeFiles/clang-tblgen.dir/ClangCommentCommandInfoEmitter.cpp.obj tools/clang/utils/TableGen/CMakeFiles/clang-tblgen.dir/ClangCommentHTMLNamedCharacterReferenceEmitter.cpp.obj tools/clang/utils/TableGen/CMakeFiles/clang-tblgen.dir/ClangCommentHTMLTagsEmitter.cpp.obj tools/clang/utils/TableGen/CMakeFiles/clang-tblgen.dir/ClangDataCollectorsEmitter.cpp.obj tools/clang/utils/TableGen/CMakeFiles/clang-tblgen.dir/ClangDiagnosticsEmitter.cpp.obj tools/clang/utils/TableGen/CMakeFiles/clang-tblgen.dir/ClangOpcodesEmitter.cpp.obj tools/clang/utils/TableGen/CMakeFiles/clang-tblgen.dir/ClangOpenCLBuiltinEmitter.cpp.obj tools/clang/utils/TableGen/CMakeFiles/clang-tblgen.dir/ClangOptionDocEmitter.cpp.obj tools/clang/utils/TableGen/CMakeFiles/clang-tblgen.dir/ClangSACheckersEmitter.cpp.obj tools/clang/utils/TableGen/CMakeFiles/clang-tblgen.dir/ClangSyntaxEmitter.cpp.obj tools/clang/utils/TableGen/CMakeFiles/clang-tblgen.dir/ClangTypeNodesEmitter.cpp.obj tools/clang/utils/TableGen/CMakeFiles/clang-tblgen.dir/MveEmitter.cpp.obj tools/clang/utils/TableGen/CMakeFiles/clang-tblgen.dir/NeonEmitter.cpp.obj tools/clang/utils/TableGen/CMakeFiles/clang-tblgen.dir/RISCVVEmitter.cpp.obj tools/clang/utils/TableGen/CMakeFiles/clang-tblgen.dir/SveEmitter.cpp.obj tools/clang/utils/TableGen/CMakeFiles/clang-tblgen.dir/TableGen.cpp.obj -o bin\clang-tblgen.exe -Xlinker /MANIFEST:EMBED -Xlinker /implib:lib\clang-tblgen.lib -Xlinker /pdb:bin\clang-tblgen.pdb -Xlinker /version:0.0 lib/LLVMSupport.lib lib/LLVMTableGen.lib lib/clangSupport.lib lib/LLVMSupport.lib lib/LLVMDemangle.lib -lkernel32 -luser32 -lgdi32 -lwinspool -lshell32 -lole32 -loleaut32 -luuid -lcomdlg32 -ladvapi32 -loldnames && cd ."
lld-link: warning: ignoring unknown argument '--gc-sections'
lld-link: error: undefined symbol: __declspec(dllimport) _CrtDbgReport
>>> referenced by tools/clang/utils/TableGen/CMakeFiles/clang-tblgen.dir/ASTTableGen.cpp.obj:(void __cdecl clang::tblgen::visitASTNodeHierarchyImpl(class llvm::RecordKeeper &, class llvm::StringRef, class llvm::function_ref<void __cdecl(class clang::tblgen::ASTNode, class clang::tblgen::ASTNode)>))
>>> referenced by tools/clang/utils/TableGen/CMakeFiles/clang-tblgen.dir/ASTTableGen.cpp.obj:(void __cdecl clang::tblgen::visitASTNodeHierarchyImpl(class llvm::RecordKeeper &, class llvm::StringRef, class llvm::function_ref<void __cdecl(class clang::tblgen::ASTNode, class clang::tblgen::ASTNode)>))
>>> referenced by tools/clang/utils/TableGen/CMakeFiles/clang-tblgen.dir/ASTTableGen.cpp.obj:(void __cdecl clang::tblgen::visitASTNodeHierarchyImpl(class llvm::RecordKeeper &, class llvm::StringRef, class llvm::function_ref<void __cdecl(class clang::tblgen::ASTNode, class clang::tblgen::ASTNode)>))
>>> referenced 5209 more times
lld-link: error: undefined symbol: __declspec(dllimport) _invalid_parameter
>>> referenced by tools/clang/utils/TableGen/CMakeFiles/clang-tblgen.dir/ASTTableGen.cpp.obj:(void __cdecl clang::tblgen::visitASTNodeHierarchyImpl(class llvm::RecordKeeper &, class llvm::StringRef, class llvm::function_ref<void __cdecl(class clang::tblgen::ASTNode, class clang::tblgen::ASTNode)>))
>>> referenced by tools/clang/utils/TableGen/CMakeFiles/clang-tblgen.dir/ASTTableGen.cpp.obj:(void __cdecl clang::tblgen::visitASTNodeHierarchyImpl(class llvm::RecordKeeper &, class llvm::StringRef, class llvm::function_ref<void __cdecl(class clang::tblgen::ASTNode, class clang::tblgen::ASTNode)>))
>>> referenced by tools/clang/utils/TableGen/CMakeFiles/clang-tblgen.dir/ASTTableGen.cpp.obj:(void __cdecl clang::tblgen::visitASTNodeHierarchyImpl(class llvm::RecordKeeper &, class llvm::StringRef, class llvm::function_ref<void __cdecl(class clang::tblgen::ASTNode, class clang::tblgen::ASTNode)>))
>>> referenced 5025 more times
lld-link: error: undefined symbol: __declspec(dllimport) _CrtSetReportHook
>>> referenced by LLVMSupport.lib(Signals.cpp.obj):(void __cdecl llvm::sys::DisableSystemDialogsOnCrash(void))
>>> referenced by LLVMSupport.lib(Signals.cpp.obj):(void __cdecl llvm::sys::PrintStackTraceOnErrorSignal(class llvm::StringRef, bool))
clang++: error: linker command failed with exit code 1 (use -v to see invocation)
[2/1992] Linking CXX executable bin\llvm-tblgen.exe
FAILED: bin/llvm-tblgen.exe
cmd.exe /C "cd . && C:\PROGRA~1\MIB055~1\2022\COMMUN~1\VC\Tools\Llvm\x64\bin\CLANG_~1.EXE -fuse-ld=lld-link -nostartfiles -nostdlib -Werror=date-time -Werror=unguarded-availability-new -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers -pedantic -Wno-long-long -Wc++98-compat-extra-semi -Wimplicit-fallthrough -Wcovered-switch-default -Wno-noexcept-type -Wnon-virtual-dtor -Wdelete-non-virtual-dtor -Wsuggest-override -Wstring-conversion -Wmisleading-indentation -Wctad-maybe-unsupported -ffunction-sections -fdata-sections -O3 -DNDEBUG -D_DLL -D_MT -Xclang --dependent-lib=msvcrt -Xlinker /subsystem:console -Wl,--gc-sections utils/TableGen/CMakeFiles/llvm-tblgen.dir/AsmMatcherEmitter.cpp.obj utils/TableGen/CMakeFiles/llvm-tblgen.dir/AsmWriterEmitter.cpp.obj utils/TableGen/CMakeFiles/llvm-tblgen.dir/AsmWriterInst.cpp.obj utils/TableGen/CMakeFiles/llvm-tblgen.dir/Attributes.cpp.obj utils/TableGen/CMakeFiles/llvm-tblgen.dir/CallingConvEmitter.cpp.obj utils/TableGen/CMakeFiles/llvm-tblgen.dir/CodeEmitterGen.cpp.obj utils/TableGen/CMakeFiles/llvm-tblgen.dir/CodeGenDAGPatterns.cpp.obj utils/TableGen/CMakeFiles/llvm-tblgen.dir/CodeGenHwModes.cpp.obj utils/TableGen/CMakeFiles/llvm-tblgen.dir/CodeGenInstruction.cpp.obj utils/TableGen/CMakeFiles/llvm-tblgen.dir/CodeGenMapTable.cpp.obj utils/TableGen/CMakeFiles/llvm-tblgen.dir/CodeGenRegisters.cpp.obj utils/TableGen/CMakeFiles/llvm-tblgen.dir/CodeGenSchedule.cpp.obj utils/TableGen/CMakeFiles/llvm-tblgen.dir/CodeGenTarget.cpp.obj utils/TableGen/CMakeFiles/llvm-tblgen.dir/DAGISelEmitter.cpp.obj utils/TableGen/CMakeFiles/llvm-tblgen.dir/DAGISelMatcherEmitter.cpp.obj utils/TableGen/CMakeFiles/llvm-tblgen.dir/DAGISelMatcherGen.cpp.obj utils/TableGen/CMakeFiles/llvm-tblgen.dir/DAGISelMatcherOpt.cpp.obj utils/TableGen/CMakeFiles/llvm-tblgen.dir/DAGISelMatcher.cpp.obj utils/TableGen/CMakeFiles/llvm-tblgen.dir/DecoderEmitter.cpp.obj utils/TableGen/CMakeFiles/llvm-tblgen.dir/DFAEmitter.cpp.obj utils/TableGen/CMakeFiles/llvm-tblgen.dir/DFAPacketizerEmitter.cpp.obj utils/TableGen/CMakeFiles/llvm-tblgen.dir/DirectiveEmitter.cpp.obj utils/TableGen/CMakeFiles/llvm-tblgen.dir/DisassemblerEmitter.cpp.obj utils/TableGen/CMakeFiles/llvm-tblgen.dir/DXILEmitter.cpp.obj utils/TableGen/CMakeFiles/llvm-tblgen.dir/ExegesisEmitter.cpp.obj utils/TableGen/CMakeFiles/llvm-tblgen.dir/FastISelEmitter.cpp.obj utils/TableGen/CMakeFiles/llvm-tblgen.dir/GICombinerEmitter.cpp.obj utils/TableGen/CMakeFiles/llvm-tblgen.dir/GlobalISelEmitter.cpp.obj utils/TableGen/CMakeFiles/llvm-tblgen.dir/InfoByHwMode.cpp.obj utils/TableGen/CMakeFiles/llvm-tblgen.dir/InstrInfoEmitter.cpp.obj utils/TableGen/CMakeFiles/llvm-tblgen.dir/InstrDocsEmitter.cpp.obj utils/TableGen/CMakeFiles/llvm-tblgen.dir/IntrinsicEmitter.cpp.obj utils/TableGen/CMakeFiles/llvm-tblgen.dir/OptEmitter.cpp.obj utils/TableGen/CMakeFiles/llvm-tblgen.dir/OptParserEmitter.cpp.obj utils/TableGen/CMakeFiles/llvm-tblgen.dir/OptRSTEmitter.cpp.obj utils/TableGen/CMakeFiles/llvm-tblgen.dir/PredicateExpander.cpp.obj utils/TableGen/CMakeFiles/llvm-tblgen.dir/PseudoLoweringEmitter.cpp.obj utils/TableGen/CMakeFiles/llvm-tblgen.dir/CompressInstEmitter.cpp.obj utils/TableGen/CMakeFiles/llvm-tblgen.dir/RegisterBankEmitter.cpp.obj utils/TableGen/CMakeFiles/llvm-tblgen.dir/RegisterInfoEmitter.cpp.obj utils/TableGen/CMakeFiles/llvm-tblgen.dir/SDNodeProperties.cpp.obj utils/TableGen/CMakeFiles/llvm-tblgen.dir/SearchableTableEmitter.cpp.obj utils/TableGen/CMakeFiles/llvm-tblgen.dir/SubtargetEmitter.cpp.obj utils/TableGen/CMakeFiles/llvm-tblgen.dir/SubtargetFeatureInfo.cpp.obj utils/TableGen/CMakeFiles/llvm-tblgen.dir/TableGen.cpp.obj utils/TableGen/CMakeFiles/llvm-tblgen.dir/Types.cpp.obj utils/TableGen/CMakeFiles/llvm-tblgen.dir/VarLenCodeEmitterGen.cpp.obj utils/TableGen/CMakeFiles/llvm-tblgen.dir/X86DisassemblerTables.cpp.obj utils/TableGen/CMakeFiles/llvm-tblgen.dir/X86EVEX2VEXTablesEmitter.cpp.obj utils/TableGen/CMakeFiles/llvm-tblgen.dir/X86FoldTablesEmitter.cpp.obj utils/TableGen/CMakeFiles/llvm-tblgen.dir/X86MnemonicTables.cpp.obj utils/TableGen/CMakeFiles/llvm-tblgen.dir/X86ModRMFilters.cpp.obj utils/TableGen/CMakeFiles/llvm-tblgen.dir/X86RecognizableInstr.cpp.obj utils/TableGen/CMakeFiles/llvm-tblgen.dir/WebAssemblyDisassemblerEmitter.cpp.obj utils/TableGen/CMakeFiles/llvm-tblgen.dir/CTagsEmitter.cpp.obj -o bin\llvm-tblgen.exe -Xlinker /MANIFEST:EMBED -Xlinker /implib:lib\llvm-tblgen.lib -Xlinker /pdb:bin\llvm-tblgen.pdb -Xlinker /version:0.0 lib/LLVMSupport.lib lib/LLVMTableGen.lib lib/LLVMTableGenGlobalISel.lib lib/LLVMTableGen.lib lib/LLVMSupport.lib lib/LLVMDemangle.lib -lkernel32 -luser32 -lgdi32 -lwinspool -lshell32 -lole32 -loleaut32 -luuid -lcomdlg32 -ladvapi32 -loldnames && cd ."
lld-link: warning: ignoring unknown argument '--gc-sections'
lld-link: error: undefined symbol: __declspec(dllimport) _CrtDbgReport
>>> referenced by utils/TableGen/CMakeFiles/llvm-tblgen.dir/AsmMatcherEmitter.cpp.obj:(public: void __cdecl `anonymous namespace'::AsmMatcherEmitter::run(class llvm::raw_ostream &))
>>> referenced by utils/TableGen/CMakeFiles/llvm-tblgen.dir/AsmMatcherEmitter.cpp.obj:(public: void __cdecl `anonymous namespace'::AsmMatcherEmitter::run(class llvm::raw_ostream &))
>>> referenced by utils/TableGen/CMakeFiles/llvm-tblgen.dir/AsmMatcherEmitter.cpp.obj:(public: void __cdecl `anonymous namespace'::AsmMatcherEmitter::run(class llvm::raw_ostream &))
>>> referenced 13261 more times
lld-link: error: undefined symbol: __declspec(dllimport) _invalid_parameter
>>> referenced by utils/TableGen/CMakeFiles/llvm-tblgen.dir/AsmMatcherEmitter.cpp.obj:(public: void __cdecl `anonymous namespace'::AsmMatcherEmitter::run(class llvm::raw_ostream &))
>>> referenced by utils/TableGen/CMakeFiles/llvm-tblgen.dir/AsmMatcherEmitter.cpp.obj:(public: void __cdecl `anonymous namespace'::AsmMatcherEmitter::run(class llvm::raw_ostream &))
>>> referenced by utils/TableGen/CMakeFiles/llvm-tblgen.dir/AsmMatcherEmitter.cpp.obj:(public: void __cdecl `anonymous namespace'::AsmMatcherEmitter::run(class llvm::raw_ostream &))
>>> referenced 13252 more times
lld-link: error: undefined symbol: __declspec(dllimport) _CrtSetReportHook
>>> referenced by LLVMSupport.lib(Signals.cpp.obj):(void __cdecl llvm::sys::DisableSystemDialogsOnCrash(void))
>>> referenced by LLVMSupport.lib(Signals.cpp.obj):(void __cdecl llvm::sys::PrintStackTraceOnErrorSignal(class llvm::StringRef, bool))
clang++: error: linker command failed with exit code 1 (use -v to see invocation)
ninja: build stopped: subcommand failed.