Community Documents

cancel
Showing results for 
Search instead for 
Did you mean: 

How-to build and integrate lastest clang compiler to CVI 2013 IDE

Overview

Unfficial guide about how-to build lastest version of clang compiler and how to integrate it to CVI IDE.

This is targeted to people who need that nice new warning messages that native CVI compiler does not have yet.

Please feel free to edit this guide, but please do not remove Warnings ahead section.

Warnings ahead:

CVI can use clang as external compiler for release builds, but CVI allways use its own linker, this can lead to potential incompatibility!

I do not reccomend to use clang + CVI for production-distribution, at least without detailed testing!

Last warning:!Using different and/or non official compiler can bring serious problems. Some of them appear quickly, some can be very well hidden for very long time. Please be careful!

Note about compiler warnings and optimization:

Using different optimization settings/level will show or hide some bugs or warnings, this is by desing of compiler.

(especially in the case of using Undefined or Unspecified behaviour - by ansi-c specification)

Use it to your advantage.Try to compile your project with and without maximum optimization, even if you do not use it for production-distribution.

Using precompiled clang binaries

It is posible to use prebuild binaries. I test it a little and it seems that project can be compiled and executed.

I do not have deep knowledge about this, but it seems to me that there are potential problem because the prebuiltclang compiler has its target preset to _M_IX86=500 and CVI compiler template force the compiler to _M_IX86=400. I gues that CVI linker (which is used anyway) need this.

Also prebuilt clang will  throw 3 line of warnings about _M_IX86 redefinition to every compiled file.

However, this can be suppresed by commandline parameters.

I do not like to have that warning suppresion on global level, so, togheter with "_M_IX86=500" potential problem, i still reccomend to  modify the source code and build customized version of clang.

If you are still interested, there it is the "easy" way:

  1. download and instal prebuilt clang from windows on http://llvm.org/releases/download.html
    (It is beter to avoid space characters in directory path)
  2. continue to paragraph "Integration of clang to CVI IDE" but add the commandline parameter bellow to external compiler "additional flags" or "Warning level customization:"
    -Wno-macro-redefined

Build clang from source code (SVN repositories) and make it compatible with CVI

  1. I use "Microsoft Visual studio express 2013 for desktop" to compile clang from source code
    (You need to create account to get it, but it is free. I do not cover registration and instalation of Visual Studio in this guide.)
  2. Get fresh version of clang and tools to build them using visual studio
    I use official guide on: http://clang.llvm.org/get_started.html  (there is section called "Using Visual Studio")
    • Instead of Subversion, i use TortoiseSVN - but you need to select commandline support during instalation
    • Python is need for build clang, not only for tests(there is wrong info on that page)
    • We need to modify some sources, so stop before "Build Clang" part.
      (you can build and use it without modification, but this will lead to lot of warning messages when used from CVI)
    • folowing that guide, you get lastest development version  - "trunk". this is not stable release!!! You should not use it for production.
      To get stable release , you need to change the svn command, I build the compiler and try to use it in CVI susscefuly, but i do not test much.
      (you can open the svn path in your internet browser to find all possible versions/tags)
      svn co http://llvm.org/svn/llvm-project/llvm/tags/RELEASE_351/Final/ llvm
      svn co http://llvm.org/svn/llvm-project/cfe/tags/RELEASE_351/final/ clang
    • for Visual studio 2013, cmake command should be changed to
      cmake -G "Visual Studio 12" ..\llvm
  3. Modify clang to be more compatible with CVI2013 compatibility
    • notes:In the current CVI version (2013), CVI use compatibility with visual studio, but it also setting target platform to _M_IX86=400
      In clang however, this is preset to _M_IX86=500  (for visual studio target). And because _M_IX86 constant cannot be redefined, clang throw warning message about this for every compiled file.
    • To resolve this, you need to change or remove this default definition from clang visal studio target. (I chose to remove that definition:)
      • open the file    :  Clang\llvm\tools\clang\lib\Basic\Targets.cpp
      • search for section:  // x86-32 Windows Visual Studio target
      • comment the line starting with :  Builder.defineMacro("_M_IX86", "600");
      • After that, cvi can set _M_IX86=400 on command line without problems
  4. Build clang compiler
    • Open LLVM.sln (in visual studio) and build the solution.
    • After some long time of compilation. there should be compiled compiler file Clang\Build\Debug\bin\clang.exe
    • You can move clang.exe and *.dll files to another directory if you wish.
      But i recommend that there is no space character in the path (not like "\Clang compiler\...\")

Integration of clang to CVI IDE

  1. Create new  CVI external compiler configuration
    • This is hidden in CVI Ide ->menu options->tab Build process options\Active 32bit compiler

    • clang2.9 template work well, just change path to your clang.exe file.

    • Warnings for external compiler cannot be configured by CVI IDE dialog(Build options\Compiler options\Compiler warnings)
      You need to manage them from external compiler configuration dialog.
      • I recommend to start with "more warnings" profile and edit them as needed.
        (i.e I suppres some warnings like -Wno-pointer-sign)
      • Lot of compiler warnings contains its "commandline switch" how to disable it, some of them don`t.
      • Unfortunately, there are not good list of warning switches for clang yet, you can find something like http://dennycd.me/clang-warning-flag-list/ but they are not complet and without details.
      • In the meantime, GCC documentation is good enought: https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html

  2. Make CVI stdint.h compatible with new compiler
    • Check your clang version from command line clang.exe --version command
    • !For all following changes, you need to have administrator rights!
      !you need to run your favorite "file manager" and "editor" with "Run as administrator"!
    • Create new folder with number of version of clang compiler (3.7 in my case) in your CVI compiler directory like
      c:\Program Files (x86)\National Instruments\CVI2013\include\clang\3.7
    • copy stdint.h file from clang build directory Clang\Build\Debug\lib\clang\3.7.0\include\ to that directory above
      (I copy all clang header files, but this is not nesccesary i think)
    • Open file c:\Program Files (x86)\National Instruments\CVI2013\include\ansi\stdint.h for editation:
    • Somewhere on start of the file, there is section that check clang compiler and his version.
      for my CVI2013 it looks like this:

      #if __clang_major__ == 2 && __clang_minor__ == 9

      #include <clang/2.9/stdint.h>

      #else // clang 1.0 does not define version numbers

      #include <clang/stdint.h>

      #endif

    • To Add new clang support you need to modify it like this:
      (please update or comment __clang_minor__ test to number of your compiler version)

      #if __clang_major__ == 3 && __clang_minor__ == 7

      //This #pragma is for suppres warnings about macro redefinition.

      //This can also be achieved by add #undef ... before macro redefinition in clang/3.7/stdint.h

      #pragma clang diagnostic push

      #pragma clang diagnostic ignored "-Wbuiltin-macro-redefined"

      #pragma clang diagnostic ignored "-Wmacro-redefined"

      #include <clang/3.7/stdint.h>

      #pragma clang diagnostic pop

      #elif __clang_major__ == 2 && __clang_minor__ == 9

      #include <clang/2.9/stdint.h>

      #else // clang 1.0 does not define version numbers

      #include <clang/stdint.h>

      #endif

Requirements

Software

Microsoft Visual Studio Express 2013

Subversion or TortoiseSVN

Python for windows

Cmake

Comments
User002
Not applicable
on

Thank you very much, particularly for your step 6!

Personally I probably will skip your steps 1 - 4 using prebuilt windows binaries that are available at the LLVM Download Page

OVR_CZ
Member
Member
on

I try prebuilt binaries before, but there are some problems with them.

So i move to source code and my customized clang build.

However, it is lot faster to make it work. So i add that way to guide too. Together with some reason why i avoid that.

Contributors