LLVM build options for ARM / RaspberryPi

后端 未结 1 1741
不知归路
不知归路 2020-12-29 16:30

I\'m seeking clarification of what the best build options are for LLVM 3.2 on Raspbian

I\'ve fetched the LLVM source of 3.2, and my config is:

cd llv         


        
相关标签:
1条回答
  • 2020-12-29 16:37

    I'd recommend cross-compiling LLVM for Raspbian. Building it on Pi itself takes ages.

    First, get a working root fs using debootstrap (alternatively, just clone your existing Raspbian installation or unpack a downloaded image). You may need to replace some absolute symlinks with relative, watch out for build errors.

    Make sure you have a working and recent enough installation of clang (don't forget to build it with ARM target support).

    Then, cross-compile LLVM with the following CMake toolchain definition (you should not chroot into your root fs at this stage!):

    
    set(toolchain_dir /path/to/your/chroot-raspbian-armhf/ )
    set(toolchain_bin_dir ${toolchain_dir}/usr/bin)
    set(toolchain_inc_dir ${toolchain_dir}/usr/include) # was /include
    set(toolchain_lib_dir ${toolchain_dir}/usr/lib)
    
    set(CMAKE_SYSTEM_NAME Linux CACHE INTERNAL "system name")
    set(CMAKE_SYSTEM_PROCESSOR arm CACHE INTERNAL "processor")
    set(CMAKE_C_COMPILER clang)
    set(CMAKE_CXX_COMPILER clang++)
    set(CMAKE_C_FLAGS "-O2 -integrated-as -target armv6-linux-gnueabihf -mfloat-abi=hard --sysroot=${toolchain_dir}" CACHE INTERNAL "c compiler flags")
    set(CMAKE_CXX_FLAGS "-O2 -integrated-as -target armv6-linux-gnueabihf -mfloat-abi=hard --sysroot=${toolchain_dir}" CACHE INTERNAL "cxx compiler flags")
    
    set(link_flags "-L${toolchain_lib_dir} -ldl")
    
    set(CMAKE_EXE_LINKER_FLAGS ${link_flags} CACHE INTERNAL "exe link flags")
    set(CMAKE_MODULE_LINKER_FLAGS ${link_flags} CACHE INTERNAL "module link flags")
    set(CMAKE_SHARED_LINKER_FLAGS ${link_flags} CACHE INTERNAL "shared link flags")
    set(CMAKE_FIND_ROOT_PATH ${toolchain_lib_dir} CACHE INTERNAL "cross root directory")
    set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM BOTH CACHE INTERNAL "")
    set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY CACHE INTERNAL "")
    set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY CACHE INTERNAL "")
    

    (use cmake -DCMAKE_TOOLCHAIN_FILE=/path/to/the/file/above.txt)

    Please note that target should be armv6-linux-gnueabihf, not armv6-linux-gnueabi.

    0 讨论(0)
提交回复
热议问题