Hi I want to cross compile from Mac to Linux arm. I am trying to use clang to do this. I figured out that Apple clang couldn’t do it so used LLVM clang. I installed it using homebrew.
brew install llvm
I then followed this page to cross compile: https://mcilloni.ovh/2021/02/09/cxx-cross-clang/
This worked well. I am able to do this command to compile a file:
/usr/local/opt/llvm/bin/clang++ --target=armv7a-linux-gnueabihf --sysroot=orangepi_sysroot -mfloat-abi=hard -mthumb -march=armv7-a+fp -mtune=cortex-a7 -mfpu=neon-vfpv3 -Wno-psabi -stdlib=libstdc++ -fuse-ld=lld main.cpp -o cross_compile_test
This seemed to be fine and I could run the output on the arm device.
I then wanted to use this in my cmake project (interestingly the link above does show cmake but leaves out the linker option or how to specify a linker) and I set up a toolchain file like this:
set(CMAKE_SYSTEM_NAME Linux)
set(CMAKE_SYSTEM_PROCESSOR arm)
set(CMAKE_SYSROOT /<path-to>/orangepi_sysroot)
set(CMAKE_AR /usr/local/opt/llvm/bin/llvm-ar)
set(CMAKE_ASM_COMPILER /usr/local/opt/llvm/bin/llvm-as)
set(CMAKE_C_COMPILER /usr/local/opt/llvm/bin/clang)
set(CMAKE_CXX_COMPILER /usr/local/opt/llvm/bin/clang++)
set(CMAKE_LINKER /usr/local/opt/llvm/bin/ld.lld)
set(CMAKE_CXX_LINK_EXECUTABLE /usr/local/opt/llvm/bin/ld.lld)
set(CMAKE_OBJCOPY /usr/local/opt/llvm/bin/llvm-objcopy)
set(CMAKE_RANLIB /usr/local/opt/llvm/bin/llvm-ranlib)
set(CMAKE_SIZE /usr/local/opt/llvm/bin/llvm-size)
set(CMAKE_STRIP /usr/local/opt/llvm/bin/llvm-strip)
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)
SET(CMAKE_C_FLAGS "--target=armv7a-linux-gnueabihf --sysroot=/<path-to>/orangepi_sysroot -mfloat-abi=hard -mthumb -march=armv7-a -mtune=cortex-a7 -mfpu=neon-vfpv3 -Wno-psabi -stdlib=libstdc++ -fuse-ld=lld -v" CACHE STRING "" FORCE)
SET(CMAKE_CXX_FLAGS "--target=armv7a-linux-gnueabihf --sysroot=/<path-to>/orangepi_sysroot -mfloat-abi=hard -mthumb -march=armv7-a -mtune=cortex-a7 -mfpu=neon-vfpv3 -Wno-psabi -stdlib=libstdc++ -fuse-ld=lld -v" CACHE STRING "" FORCE)
I used a very similar toolchain file when cross compiling from linux host to linux arm and it worked well.
The above give this error:
clang++: error: argument unused during compilation: '-fuse-ld=lld' [-Werror,-Wunused-command-line-argument]
I have tried removing that option from the compile flags and adding it to LINK_OPTIONS
and CMAKE_EXE_LINKER_FLAGS
and it didn’t help. I get the following:
ld.lld: error: no input files
I think the issue is around using the correct linker, does anyone know how to set that correctly using cmake?