Author Topic: LLVM/Clang compiler for MinGW  (Read 48823 times)

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9694
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: https://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: https://wiki.codeblocks.org/index.php?title=FAQ

Offline golgepapaz

  • Multiple posting newcomer
  • *
  • Posts: 44
Re: LLVM/Clang compiler for MinGW
« Reply #1 on: January 23, 2013, 02:08:17 am »
You can build it yourself. configure or cmake based builds works out of the box..
I do have two modifications to the source code, one pertaining to clang unable to find
mingw header files (4.7.2, 4.7.3 etc) and one about calling convention if you happen upon
some problems..

Interestingly I'd come to report nullptr causing problems with clang because definition in
prep.h does not consider clang.
Code
#if !(__GNUC__ == 4 && __GNUC_MINOR__ >= 6 && defined __GXX_EXPERIMENTAL_CXX0X__)
    // it is a const object...
    const class nullptr_t
    {
    public:
        // constructor
        nullptr_t() {}
        // convertible to any type of null non-member pointer...
        template<typename T> operator T* () const{ return (T*)0; }
        // or any type of null member pointer...
        template<typename C, typename T> operator T C::* () const { return (T C::*)0; }
        // support operator overloading (== and !=)
        template<typename T> bool equals(T const& rhs) const { return rhs == 0; }
    private:
        // can't take address of nullptr
        void operator&() const;
        // can't copyable
        nullptr_t(const nullptr_t&);
        const nullptr_t& operator=(const nullptr_t&);
    } nullptr_;
    #define nullptr nullptr_
#endif
it needs also something like
#if !(__has_feature(cxx_nullptr))

Clang does not use something like GXX_EXPERIMENTAL_CXX0X or version numbers but instead opts for
__has_feature macro to query if certain language features are enabled.

http://clang.llvm.org/docs/LanguageExtensions.html#checking_upcoming_features

Offline vwdvaan

  • Multiple posting newcomer
  • *
  • Posts: 15
Re: LLVM/Clang compiler for MinGW
« Reply #2 on: May 01, 2013, 10:47:22 am »
Win 10, MinGW 122.0, wxWidgets 3.1.7

Offline eranif

  • Regular
  • ***
  • Posts: 256
Re: LLVM/Clang compiler for MinGW
« Reply #3 on: May 01, 2013, 12:57:59 pm »
Quote
I am looking for a LLVM/Clang compiler suite that works under Win32.
These I tried, but they all fail with crashes, missing libraries or alike:
I have it self compiled on my machine with TDM-GCC-4.7.1. i.e. in order for it to work you also need to install TDM-GCC-4.7.1

HOWEVER, (and this is a big _HOWEVER_): gdb (Windows only) can not debug binaries created with clang under Windows
I opened a bug for this here:

http://llvm.org/bugs/show_bug.cgi?id=13636

There is patch for this bug which I am not sure it was applied...( I will test with latest trunk tonight):
http://lists.cs.uiuc.edu/pipermail/llvmdev/2012-November/056009.html

Drop me a message if you want me to upload my compiled version

Eran

Offline xunxun

  • Almost regular
  • **
  • Posts: 187
Re: LLVM/Clang compiler for MinGW
« Reply #4 on: May 01, 2013, 05:16:31 pm »

There is patch for this bug which I am not sure it was applied...( I will test with latest trunk tonight):
http://lists.cs.uiuc.edu/pipermail/llvmdev/2012-November/056009.html


Is the patch effective for debugging after your test?
Regards,
xunxun

Offline eranif

  • Regular
  • ***
  • Posts: 256
Re: LLVM/Clang compiler for MinGW
« Reply #5 on: May 02, 2013, 01:40:30 pm »
Hi xunxun,
I did not apply the patch locally...so I can't really answer your question
I settled for opening a ticket to the clang devs
Eran

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9694
Re: LLVM/Clang compiler for MinGW
« Reply #6 on: May 02, 2013, 03:33:21 pm »
Drop me a message if you want me to upload my compiled version
Drop. :-)

Maybe there is already a 3.2 version? I also read the current dev-version supports c++11 completely - that would be interesting, too.

The thing with gdb is bad, indeed. :-/
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: https://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: https://wiki.codeblocks.org/index.php?title=FAQ

Offline eranif

  • Regular
  • ***
  • Posts: 256
Re: LLVM/Clang compiler for MinGW
« Reply #7 on: May 02, 2013, 07:17:18 pm »
Updating clang/llvm to their latest trunk and building
I will also check if gdb is working with latest trunk.. (thought I doubt it will work...)

Eran

Offline eranif

  • Regular
  • ***
  • Posts: 256
Re: LLVM/Clang compiler for MinGW
« Reply #8 on: May 03, 2013, 06:01:14 am »
Hi,

I built clang latest trunk + I did some minor change to allow debugging - with the my build you can compile and debug a C program.
For C++: Its not usable.

- Exceptions are not supported (you need to compile your code with -fno-exceptions)
- You need to explicitly set -lstd++ in the linker
- After you successfully link, your program will crash ;) ( in debug and release mode with no optimizations ) with non helpful backtrace. Note that the crash happens with or without my change

To summarize:
- Is usable for C
- Don't bother with it for C++ / Windows

Linux is another story:
- Works like a charm (I even got a separate codelite build which compiles with clang)
- Its x2 faster than g++ on linux (for comparison, compiling codelite ~1200 sources with PCH enabled takes about 3 mins on my 8 core machine with g++ and ~1.3 min with clang++)
- A drop in replacement for g++/gcc (just set CXX=clang++ / CC=clang and you are done)

Eran

Offline killerbot

  • Administrator
  • Lives here!
  • *****
  • Posts: 5491
Re: LLVM/Clang compiler for MinGW
« Reply #9 on: May 03, 2013, 07:39:19 am »
how do you build it on linux ? I know it is in the repos, but I think their new libstd++ is missing for linux, and that one should be build , right ?
And does the C++11 stuff work ?

Offline eranif

  • Regular
  • ***
  • Posts: 256
Re: LLVM/Clang compiler for MinGW
« Reply #10 on: May 03, 2013, 08:08:37 am »
Building on Linux is quite straight forward:

http://codelite.org/Developers/HomePage#toc2

Once you have completed the above steps - just run
Code
sudo make install

To build their libc++ (this is what I am using to build it on my linux box):

Code
svn co http://llvm.org/svn/llvm-project/libcxx/trunk libcxx
cd libcxx
mkdir build-release
cmake -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=Release ..
make -j8
sudo make install

You can get more details here:
http://libcxx.llvm.org/

Eran

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9694
Re: LLVM/Clang compiler for MinGW
« Reply #11 on: May 03, 2013, 10:11:53 am »
For C++: Its not usable.
So: Am I getting it right that I am still lost on Windows? :-(
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: https://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: https://wiki.codeblocks.org/index.php?title=FAQ

Offline eranif

  • Regular
  • ***
  • Posts: 256
Re: LLVM/Clang compiler for MinGW
« Reply #12 on: May 03, 2013, 10:16:04 am »
Yes you are ;)

Maybe building clang with Visual Studio will help - but you mentioned that you wanted a MinGW version...


Eran



Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9694
Re: LLVM/Clang compiler for MinGW
« Reply #13 on: May 03, 2013, 10:29:55 am »
Maybe building clang with Visual Studio will help - but you mentioned that you wanted a MinGW version...
Yes, that's explicitely what I am looking for. The VS version I use works flawlessly. I am using the one from here:
http://www.ishani.org/web/articles/code/clang-win32/

BTW:
i686-w64-mingw32-clang-3.1-release-win32_rubenvb.7z with i686-w64-mingw32-gcc-dw2-4.6.3-2-release-win32_rubenvb.7z
Create a dir LLVM and copy in that dir.
...does not work, too. I can compile a simple main doing nothing, but as soon as you start to use C++ it fails miserably as all others.

Nevermind... seems there is no prime time yet... But thanks anyways...
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: https://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: https://wiki.codeblocks.org/index.php?title=FAQ

Offline Alpha

  • Developer
  • Lives here!
  • *****
  • Posts: 1513
Re: LLVM/Clang compiler for MinGW
« Reply #14 on: May 03, 2013, 04:00:17 pm »
...does not work, too. I can compile a simple main doing nothing, but as soon as you start to use C++ it fails miserably as all others.
Some time ago, I built it with MinGW and got C++ to work.  There are some hard-coded search paths for STL headers that I had to modify first (sorry, I cannot recall which file they were in).