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/

  • 相关阅读:
    Unity 绘制带颜色的流线 streamline
    Tinyply 源码阅读
    题解 [BZOJ2952]长跑
    莫比乌斯反演技巧
    题解 pyh的求和
    Java Web基础
    后端常用数据持久层模板及框架以及一些工具类模板的配置使用集合
    12306火车订票系统(C++)
    C++/Java文件读写并执行相关操作、文件复制、文件格式转换等(举例)
    《Java EE编程技术》综合应用系统开发_作业管理系统_Struts2_设计报告
  • 原文地址:https://www.cnblogs.com/stonehat/p/7000637.html
Copyright © 2011-2022 走看看