Using clang with codeblocks on Windows 7

前端 未结 3 1157
眼角桃花
眼角桃花 2021-02-10 13:59

I have managed to build clang on Windows 7 using Visual Studio 210 and now I like to use it with the codeblocks IDE. So I copied the clang executables into the mingw bin\\ folde

相关标签:
3条回答
  • 2021-02-10 14:29

    clang does not support MSVC C++ ABI yet so C++ code cannot be compiled correctly.

    Update: As of December 2014, clang does support MSVC except (heh) exceptions. To compile code you will have to do

    clang-cl.exe /D_HAS_EXCEPTIONS=0 foo.cpp
    

    If you want to use clang.exe directly:

    clang++ -target i686-pc-windows-msvc -D_HAS_EXCEPTIONS=0 foo.cpp -o foo.exe
    

    etc.

    For up to date status of MSVC support see http://clang.llvm.org/docs/MSVCCompatibility.html

    0 讨论(0)
  • 2021-02-10 14:37

    My CodeBlocks build logs show command lines as

    clang++.exe -fno-ms-compatibility -fno-use-cxa-atexit -IC:\mingw\include\c++\4.7.0 -IC:\mingw\include\c++\4.7.0\x86_64-w64-mingw32 -IC:\mingw\include\c++\4.7.0\backward -IC:\mingw\include -c C:\Users\Vipul\Documents\Hello.cpp -o C:\Users\Vipul\Documents\Hello.o

    ld.exe -oC:\Users\Vipul\Documents\Hello.exe C:\Users\Vipul\Documents\Hello.o -m i386pep -Bdynamic -Lc:\mingw\lib c:\mingw\lib\crt2.o c:\mingw\lib\crtbegin.o -lstdc++ -lmingw32 -lgcc_s -LC:\Windows\SUA\opt\gcc64\lib\gcc\x86_64-pc-interix6\4.6.0 -lgcc -lmoldname -lmingwex -lmsvcrt -ladvapi32 -lshell32 -luser32 -lkernel32 c:\mingw\lib\crtend.o

    and I can run the program. I've built Windows clang with VSExpress. If compilation or link is causing errors on your end, then comparing our command lines might help isolate the issue.

    0 讨论(0)
  • 2021-02-10 14:40

    UPDATE

    MSYS2 packages are available for clang on 32-bit and 64-bit, and from what limited testing I did it seems to work quite well. The compiler can be used from outside the MSYS2 environment.

    On how to install MSYS2, see here. Then just run

    pacman -Sy mingw-w64-x86_64-clang
    

    or

    pacman -Sy mingw-w64-i686-clang
    

    after updating MSYS2 to install Clang.

    The patches used in that package (if you want to build LLVM/Clang yourself) are located here.


    old reply follows, slightly out of date

    If you want to use Clang on Windows for C++, your only option currently is to use (or build yourself) Clang with/for MinGW(-w64).

    Lucky for you, I provide packages:

    • Clang 3.2
    • GCC 4.6.3 dw2

    Unzip both to the same directory and add mingw32-dw2/bin to PATH, or point Codeblocks to it. You will be limited to GCC 4.6's libstdc++. Clang 3.2's C++11 language support is fully functional though.

    Note that Clang expects GCC style options, so I suggest modifying the Codeblocks GCC build process and replacing g++ with clang++ and gcc with clang.

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