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

Offline killerbot

  • Administrator
  • Lives here!
  • *****
  • Posts: 5491
Re: LLVM/Clang compiler for MinGW
« Reply #15 on: May 04, 2013, 07:40:35 pm »
on your instructions for building libcxx :
Code
mkdir build-release
cd  build-release  <======================
cmake -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=Release ..

Offline killerbot

  • Administrator
  • Lives here!
  • *****
  • Posts: 5491
Re: LLVM/Clang compiler for MinGW
« Reply #16 on: May 04, 2013, 07:59:19 pm »
build and installed clang and libc++ with your instructions, then let CB autodetect it, it finds it in /usr/local/clang.

But when trying a "hello world" , it fails to compile since it doesn't ind the headers (iostream).
What should be the correct location ?
Timestamps wise I think this was a result of the build too : /usr/local/include/c++/v1/ ? => when using this , compiles but now linker problems (eg . :  main.cpp:4: undefined reference to `std::__1::cout')

Also my linux shell doesn't seem to know  about clang (yet), though I did ldconfig, and /usr/local/bin is already in my path (this is also where codeblocks executable is).

EDIT : on the linking problem : added to Cb for clang compiler settings :
linker path : /usr/local/lib
link lib : c++

==> links but at run time :  error while loading shared libraries: libc++.so.1: cannot open shared object file: No such file or directory
« Last Edit: May 04, 2013, 08:13:07 pm by killerbot »

Offline eranif

  • Regular
  • ***
  • Posts: 256
Re: LLVM/Clang compiler for MinGW
« Reply #17 on: May 05, 2013, 07:27:57 am »
I forgot to mention that you will need libc++abi as well.., building it on linux does not work "out-of-the-box" but requires a small tweak:

First, checkout libcxxabi:

Code
 svn co http://llvm.org/svn/llvm-project/libcxxabi/trunk libcxxabi

Next:
Code
cd libcxxabi/lib

Now you need to add some include paths... otherwise it will not compile:
run:
Code
 g++ -v  -x c++ /dev/null -fsyntax-only

Locate the output line which is similar to this:
Code
/usr/lib/gcc/x86_64-linux-gnu/4.7/include

Adjust CXX environment variable so it will be something similar to this:
Code
export CXX='clang++ -I/usr/local/include/c++/v1 -I/usr/lib/gcc/x86_64-linux-gnu/4.7/include'
and compile libcxxabi by simply typing:
Code
./buildit

once the compilation is done, you should have a new lib: libc++abi.so.1.0
I could not find a simple way of installing so I copied it manually to /usr/local/lib and created 2 symlinks:

Code
ln -sf /usr/local/lib/libc++abi.so.1.0 /usr/local/lib/libc++abi.so
ln -sf /usr/local/lib/libc++abi.so.1.0 /usr/local/lib/libc++abi.so.1

Now compiling with clang++/libc++ should be like this:

Code
clang++ -stdlib=libc++ -c test.cpp -I/usr/local/include/c++/v1
clang++ -stdlib=libc++ test.o -o TestMe -lc++ -lc++abi -I/usr/local/include/c++/v1/

Eran

Offline killerbot

  • Administrator
  • Lives here!
  • *****
  • Posts: 5491
Re: LLVM/Clang compiler for MinGW
« Reply #18 on: May 05, 2013, 09:49:39 am »
Thanks Eran, but not yet ok for me :

Code
error while loading shared libraries: libc++abi.so.1: cannot open shared object file: No such file or directory

Offline eranif

  • Regular
  • ***
  • Posts: 256
Re: LLVM/Clang compiler for MinGW
« Reply #19 on: May 05, 2013, 09:52:10 am »
Did you remember to add /usr/local/lib to LD_LIBRARY_PATH?

Code
export LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH

In addition, note that you should create 2 symlinks

Code
ln -sf /usr/local/lib/libc++abi.so.1.0 /usr/local/lib/libc++abi.so
ln -sf /usr/local/lib/libc++abi.so.1.0 /usr/local/lib/libc++abi.so.1

Eran

Offline killerbot

  • Administrator
  • Lives here!
  • *****
  • Posts: 5491
Re: LLVM/Clang compiler for MinGW
« Reply #20 on: May 05, 2013, 10:45:20 am »
I did not do the export (export LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH) , but it is in my normal path, is that not sufficient ?
And in the compiler settings of clang in CB, I even added that path as the dirs where the linker can go find libs.

I did create the 2 symlinks.

Offline eranif

  • Regular
  • ***
  • Posts: 256
Re: LLVM/Clang compiler for MinGW
« Reply #21 on: May 05, 2013, 11:16:51 am »
Quote
but it is in my normal path, is that not sufficient
Do you mean its in your PATH environment variable? LD_LIBRARY_PATH is for locating libraries during runtime
PATH is used to locate binaries (unlike Windows...)

Quote
I even added that path as the dirs where the linker can go find libs
And from what I understood the linker did _find_ it. Its just that the runtime linker did not find them (it needs LD_LIBRARY_PATH)

Eran

Offline killerbot

  • Administrator
  • Lives here!
  • *****
  • Posts: 5491
Re: LLVM/Clang compiler for MinGW
« Reply #22 on: May 05, 2013, 12:14:03 pm »
yes, it is not in my PATH ;-) /usr/local/bin is

In a console I did :
Code
killerbot@XIII:~/Projects/TryOUt/ClangC11/Deliv/Debug> ./ClangC11 
./ClangC11: error while loading shared libraries: libc++abi.so.1: cannot open shared object file: No such file or directory
killerbot@XIII:~/Projects/TryOUt/ClangC11/Deliv/Debug> export LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH
killerbot@XIII:~/Projects/TryOUt/ClangC11/Deliv/Debug> ./ClangC11
Segmentation fault

for a simple
Code
#include <iostream>

int main()
{
    std::cout << "Hello world!" << std::endl;
    return 0;
}

In /usr/local/lin I also have the boost libs from my distro. I think these can be found by programs that need it ?

In /usr/local/lib64, the codeblocks so's end up. And when CB is launched (which is located in /usr/local/bin) that one is however able to find it's so files, while that path is also not in $LD_LIBRARY_PATH

for me it is :

Code
echo $LD_LIBRARY_PATH
/usr/lib64/mpi/gcc/openmpi/lib64

So it seems there might be a few things going wrong, explicit path specification is bneeded, while other libs in there or in lib64 can be found, and in the end crash

Offline eranif

  • Regular
  • ***
  • Posts: 256
Re: LLVM/Clang compiler for MinGW
« Reply #23 on: May 05, 2013, 01:15:53 pm »
BTW, which distro do you use?

I am using Ubuntu 12.10/64
and it is running without a problem...

Can you post the compiler output and the linker ?


Eran

Offline osdt

  • Multiple posting newcomer
  • *
  • Posts: 63
Re: LLVM/Clang compiler for MinGW
« Reply #24 on: May 05, 2013, 04:21:53 pm »
build and installed clang and libc++ with your instructions, then let CB autodetect it, it finds it in /usr/local/clang.
...
Also my linux shell doesn't seem to know  about clang (yet), though I did ldconfig, and /usr/local/bin is already in my path (this is also where codeblocks executable is).
It's probably not installed in /usr/local. Try:
Code
find /usr/local -name clang++

EDIT : on the linking problem : added to Cb for clang compiler settings :
linker path : /usr/local/lib
link lib : c++
clang++ searches it's install-path/lib to find default libs.

==> links but at run time :  error while loading shared libraries: libc++.so.1: cannot open shared object file: No such file or directory
A single call to ldconfig [/usr/local/lib] shoud do it. Check if '/usr/local/lib' is in the default lib-path:
Code
grep 'usr/local' /etc/ld.so.conf

- osdt


Offline Jenna

  • Administrator
  • Lives here!
  • *****
  • Posts: 7255
Re: LLVM/Clang compiler for MinGW
« Reply #25 on: May 05, 2013, 04:23:49 pm »
I can compile C::B with clang (except for thre contrib-plugins, LibFinder, Profiler and NassiShneiderman) without any tweaking or self-compiling of clang on Fedora 18.
And it seems to run (at least it starts without issues.
C::B from inside C::B.
Compiler is detected as gcc 4.1.2 on starthere-page.

Offline Alpha

  • Developer
  • Lives here!
  • *****
  • Posts: 1513
Re: LLVM/Clang compiler for MinGW
« Reply #26 on: May 05, 2013, 05:38:53 pm »
If you do not have a particular reason to self-compile Clang, installing it through apt-get works fine.

I can compile C::B with clang (except for thre contrib-plugins, LibFinder, Profiler and NassiShneiderman) without any tweaking or self-compiling of clang on Fedora 18.
And it seems to run (at least it starts without issues.
C::B from inside C::B.
Also works in Ubuntu 12.04 and 13.04.

Offline eranif

  • Regular
  • ***
  • Posts: 256
Re: LLVM/Clang compiler for MinGW
« Reply #27 on: May 05, 2013, 07:39:54 pm »
Quote
If you do not have a particular reason to self-compile Clang, installing it through apt-get works fine
I think that the problem here is not compiling clang (from what I understand killerbot we are beyond it)
We are trying to make clang to use a different std++ library named "libc++" which on linux also requires libc++abi
both needs to be self compiled (libc++abi build instructions are only available for OSX and not for Linux not to mention Windows...)

Eran

Offline killerbot

  • Administrator
  • Lives here!
  • *****
  • Posts: 5491
Re: LLVM/Clang compiler for MinGW
« Reply #28 on: May 06, 2013, 08:00:32 pm »
all paths are in :

Code
find /usr/local -name clang++
/usr/local/bin/clang++

Code
grep 'usr/local' /etc/ld.so.conf
/usr/local/lib64
/usr/local/lib

so why does it not find the .so's

Offline osdt

  • Multiple posting newcomer
  • *
  • Posts: 63
Re: LLVM/Clang compiler for MinGW
« Reply #29 on: May 07, 2013, 01:07:36 am »
Code
grep 'usr/local' /etc/ld.so.conf
/usr/local/lib64
/usr/local/lib

so why does it not find the .so's

Hmm ... did you run ldconfig after installation of libc++ successfully? Try ...
Code
# run ldconfig
sudo /sbin/ldconfig
# check if libc++ has been found
sudo /sbin/ldconfig -p | grep 'libc++'

- osdt