zoukankan      html  css  js  c++  java
  • ubuntu下cmake 使用clang

    安装llvm、clang

    sudo apt-get install llvm clang

    clang命令会在/usr/bin/clang

    cmake配置交叉编译链

    建立linux.toolchain.cmake文件

    cmake_minimum_required( VERSION 2.6.3 )
    set(CMAKE_SYSTEM_NAME Linux )
    
    SET (CMAKE_C_COMPILER             "/usr/bin/clang")
    SET (CMAKE_C_FLAGS                "-Wall -std=c99")
    SET (CMAKE_C_FLAGS_DEBUG          "-g")
    SET (CMAKE_C_FLAGS_MINSIZEREL     "-Os -DNDEBUG")
    SET (CMAKE_C_FLAGS_RELEASE        "-O4 -DNDEBUG")
    SET (CMAKE_C_FLAGS_RELWITHDEBINFO "-O2 -g")
    
    SET (CMAKE_CXX_COMPILER             "/usr/bin/clang++")
    SET (CMAKE_CXX_FLAGS                "-Wall")
    SET (CMAKE_CXX_FLAGS_DEBUG          "-g")
    SET (CMAKE_CXX_FLAGS_MINSIZEREL     "-Os -DNDEBUG")
    SET (CMAKE_CXX_FLAGS_RELEASE        "-O4 -DNDEBUG")
    SET (CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O2 -g")
    
    SET (CMAKE_AR      "/usr/bin/llvm-ar")
    SET (CMAKE_LINKER  "/usr/bin/llvm-ld")
    SET (CMAKE_NM      "/usr/bin/llvm-nm")
    SET (CMAKE_OBJDUMP "/usr/bin/llvm-objdump")
    SET (CMAKE_RANLIB  "/usr/bin/llvm-ranlib")
    
    

    cmake命令引入交叉编译配置即可

    cmake  -DCMAKE_TOOLCHAIN_FILE=${CURRENT_SCRIPT_DIR}/linux.toolchain.cmake  .
    

    此时会显示下面一些东西,表示编译器已经换成了clang

    -- The C compiler identification is Clang 3.8.0
    -- The CXX compiler identification is Clang 3.8.0
    -- Check for working C compiler: /usr/bin/clang
    -- Check for working C compiler: /usr/bin/clang -- works
    -- Detecting C compiler ABI info
    -- Detecting C compiler ABI info - done
    -- Detecting C compile features
    -- Detecting C compile features - done
    -- Check for working CXX compiler: /usr/bin/clang++
    -- Check for working CXX compiler: /usr/bin/clang++ -- works
    -- Detecting CXX compiler ABI info
    -- Detecting CXX compiler ABI info - done
    -- Detecting CXX compile features
    -- Detecting CXX compile features - done
    
    

    注意: 如果已经运行过cmake,要先将cmake生成的文件删掉。

    转载请注明http://www.cnblogs.com/stonehat/

  • 相关阅读:
    EL+Serilog日志
    HttpClientFactory-向外请求的最佳
    Autofac依赖注入
    .Net Core MemoryCache
    时间复杂度和空间复杂度
    中间件-异常处理
    依赖注入-1
    使用并发集合
    安卓刷机&root
    Mac Android Studio 常用快捷键大全
  • 原文地址:https://www.cnblogs.com/stonehat/p/7000637.html
Copyright © 2011-2022 走看看