0

I'm using the command line tools bundled with Xcode14.3 (clang version 14.0.3), and attempting to use clang to cross compile code for the Arduino Due. Does anyone have insight on how to do this?

% clang++ main.cpp --target=arm-none-eabi -mcpu=cortex-m3
clang: error: unable to execute command: Executable "ld.lld" doesn't exist!
clang: error: ld.lld command failed with exit code 1 (use -v to see invocation)

% clang --version
Apple clang version 14.0.3 (clang-1403.0.22.14.1)
Target: x86_64-apple-darwin22.4.0
Thread model: posix
InstalledDir: /Applications/Xcode14.3.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin

% clang --target=arm-none-eabi --version
Apple clang version 14.0.3 (clang-1403.0.22.14.1)
Target: arm-none-unknown-eabi
Thread model: posix
InstalledDir: /Applications/Xcode14.3.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin

% clang++ --rtlib --target=arm-none-eabi -mcpu=cortex-m3 main.cpp
clang: error: unsupported runtime library '--target=arm-none-eabi' for platform 'darwin'
David Carpenter
  • 1,389
  • 2
  • 16
  • 29
  • Please refer: https://discourse.llvm.org/t/how-to-convert-c-to-elf-using-clang-and-using-ld-lld/65743/4 – Gaurav Pathak Apr 11 '23 at 05:20
  • i tried adding --rtlib and edited the question, how can i change the platform to arm embedded? or none? – David Carpenter Apr 11 '23 at 06:35
  • I gave up fighting the generic llvm build (apt-gotten built for x86 linux to use as arm cross compiler) so, gnu style, I built my clang/llvm/lld for the specific arm triplet, and all the problems I had trying to have code/makefile that works for more than 3 months (gnu tool code/makefiles can work for a decade or two) have gone away. even from one single digit major version to another 7.x.x, 8.x.x, ...there were problems. – old_timer Apr 11 '23 at 14:14
  • if you want to use the generic then use gnu binutils for assembly and linking. or at least linking. as you get one lld and it is for the host from what I have seen. so I dont think you can cross link without building a target specific linker (gnu or llvm). I could be wrong, – old_timer Apr 11 '23 at 14:16
  • the other tools are clang, and the bytecode to assembly language do support all the targets in a cross-build manner. – old_timer Apr 11 '23 at 14:19
  • clang is [hopelessly broken](https://stackoverflow.com/questions/59925618/how-do-i-make-an-infinite-empty-loop-that-won-t-be-optimized-away) for embedded systems purposes. Avoid like the plague. What problem would using clang specifically solve? As things stand, all clang is good for is _creating_ problems not present in any other embedded systems compiler. – Lundin Apr 13 '23 at 12:29

0 Answers0