Using clang with code blocks in Windows 7

I managed to create clang on Windows 7 using Visual Studio 210, and now I like to use it with IDE code blocks. So I copied the clang executables to the bin bin folder and updated the codeblock compiler options 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 think I need to use clang header files, but how do I do this?

Thanks!

+4
source share
3 answers

UPDATE

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

See how to install MSYS2 here . Then just run

 pacman -Sy mingw-w64-x86_64-clang 

or

 pacman -Sy mingw-w64-i686-clang 

after updating MSYS2 to install Clang.

Patches used in this package (if you want to create LLVM / Clang yourself) are located here .


old answer follows, a bit outdated

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

Luckily for you, I provide packages:

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

Note that Clang expects GCC style options, so I suggest changing the process of building GCC code and replacing g++ with clang++ and gcc with clang .

+8
source

clang does not support MSVC C ++ ABI, but C ++ code cannot be compiled correctly.

Update: as of December 2014, clang supports MSVC with the exception of (heh) exceptions. In order to compile the code, you will need 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 

and etc.

To update MSVC support status, see http://clang.llvm.org/docs/MSVCCompatibility.html

+1
source

My CodeBlocks build logs show command lines as

clang ++. exe -fno-ms-compatible -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 -C: \ Users \ Vipul \ Documents \ Hello.exe C: \ Users \ Vipul \ Documents \ Hello.o -m i386pep -Bdynamic -Lc: \ mingw \ lib c: \ mingw \ lib \ crt2.oc : \ 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 created windows clang with VSExpress. If a compilation or link causes errors at your end, then comparing our commands can help highlight the problem.

0
source

All Articles