Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using clang with codeblocks on Windows 7

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\ folder and updated the codeblock's compiler settings to use clang instead of gcc.

But when I compile the hello world example I get the following errors:

||=== clang_test, Debug ===|
obj\Debug\main.o:c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\system_error|447|undefined reference to `std::iostream_category()'|
obj\Debug\main.o:c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\stdexcept|170|undefined reference to `std::exception::exception(char const* const&)'|
||=== Build finished: 2 errors, 0 warnings ===|

I guess I have to use clang's header files but how to I accomplish that?

Thanks!

like image 968
chhenning Avatar asked Jan 15 '23 11:01

chhenning


2 Answers

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.

like image 114
rubenvb Avatar answered Jan 26 '23 00:01

rubenvb


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

like image 41
ismail Avatar answered Jan 26 '23 01:01

ismail