[cfe-dev] How to build libc++ under Linux

Michael van der Westhuizen r1mikey at gmail.com
Mon Dec 24 03:04:16 PST 2012


Hi,

This is the procedure I'm working on, and which seems to work.

I've had to apply two patches.  The Clang patch adds support for the Ubuntu Raring Ringtail (13.04) Alpha release and links libsupc++ when linking with -stdlib=libc++.  The libc++ patch avoids forceinline on functions with varargs, as that doesn't actually work.

Some (very) light testing shows that this all works, but it feels rather hackish.  You mileage will very likely vary.

Patches attached and basic compilation procedure below.  Adjust as needed for your installation.

(My next steps after verifying all of this is to get Clang built as C++11 against libc++).

Michael

-------------- next part --------------
A non-text attachment was scrubbed...
Name: clang-toolchains-bits.patch
Type: application/octet-stream
Size: 2617 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20121224/3f940253/attachment.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: libcxx-locale-linux-inline-varargs.patch
Type: application/octet-stream
Size: 960 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20121224/3f940253/attachment-0001.obj>
-------------- next part --------------


rm -rf ${HOME}/llvm-compilation
mkdir ${HOME}/llvm-compilation
cd ${HOME}/llvm-compilation
svn checkout -q http://llvm.org/svn/llvm-project/llvm/trunk llvm
cd llvm/tools
svn checkout -q http://llvm.org/svn/llvm-project/cfe/trunk clang
cd -
cd llvm/tools/clang/tools
svn co -q http://llvm.org/svn/llvm-project/clang-tools-extra/trunk extra
cd -
cd llvm/projects
svn co -q http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
cd -
svn co -q http://llvm.org/svn/llvm-project/libcxx/trunk libcxx
cd llvm/tools/clang
patch -p0 < /path/to/clang-toolchains-bits.patch
cd -
mkdir llvm-build
cd llvm-build
CC=/usr/bin/gcc \
    CXX=/usr/bin/g++ \
        ../llvm/configure \
            --prefix=/opt/clang-trunk \
            --enable-optimized \
            --disable-assertions \
            --disable-shared \
            --disable-libffi \
            --enable-targets=host \
            --disable-cxx11 \
            --disable-libcpp \
            --enable-bindings=none
make -j 3
sudo rm -rf /opt/clang-trunk
sudo make install
cd -
cd llvm/tools/clang
patch -R -p0 < /path/to/clang-toolchains-bits.patch
cd -
rm -rf llvm-build
cd libcxx
patch -p0 < /path/to/libcxx-locale.patch
cd -
sudo rm -rf /usr/local/include/c++/v1 /usr/local/lib/libc++.so.*.* /usr/local/lib/libc++.so
sudo rm -rf /usr/include/c++/v1 /usr/lib/libc++.so.*.* /usr/lib/libc++.so.* /usr/lib/libc++.so
mkdir libcxx-build
cd libcxx-build
CC=/opt/clang-trunk/bin/clang \
    CXX=/opt/clang-trunk/bin/clang++ \
    cmake \
        '-DCMAKE_BUILD_TYPE=Release' \
        '-DCMAKE_INSTALL_PREFIX=/usr' \
        '-DLIBCXX_CXX_ABI=libsupc++' \
        '-DLIBCXX_LIBSUPCXX_INCLUDE_PATHS=/usr/include/c++/4.7;/usr/include/x86_64-linux-gnu/c++/4.7' \
        ../libcxx
mkdir -p include/bits
make -j 3
sudo make install
cd -
cd libcxx
patch -R -p0 < /path/to/libcxx-locale-linux-inline-varargs.patch
cd -
rm -rf libcxx-build
cd $HOME
rm-rf llvm-compilation

On 21 Dec 2012, at 11:47 PM, François Dumont <frs.dumont at gmail.com> wrote:

> Hi
> 
>    I can't find a help mailing list so here is my message on the dev one.
> 
>    I built llvm/clang SVN trunk without any problem under my Linux box. But building libc++ is not so easy. I try
> 
> 1. Run lib/buildit
> 
> It ends up with a:
> 
> + case $TRIPLE in
> + clang algorithm.o bind.o chrono.o condition_variable.o debug.o exception.o future.o hash.o ios.o iostream.o locale.o memory.o mutex.o new.o random.o regex.o stdexcept.o string.o strstream.o system_error.o thread.o typeinfo.o utility.o valarray.o -fPIC -o libc++.so.1.0 -shared -nodefaultlibs -Wl,-soname,libc++.so.1 -lpthread -lrt -lc -lstdc++ -std=c++0x -fstrict-aliasing -Wall -Wextra -Wshadow -Wconversion -Wnewline-eof -Wpadded -Wmissing-prototypes -Wstrict-aliasing=2 -Wstrict-overflow=4
> /usr/bin/ld: cannot find crtbeginS.o: No such file or directory
> clang-3: error: linker command failed with exit code 1 (use -v to see invocation)
> 
> 2. Put libcxx within llvm/tools
> 
>    Like must be done for clang. It has no effect when building llvm.
> 
> 3. Use cmake
> 
>    I have created a build-libcxx folder next to ibcxx and call
> 
> cmake ../libcxx
> 
>  from it. The result is:
> 
> -- Looking for __gcc_personality_v0 in gcc_s
> -- Looking for __gcc_personality_v0 in gcc_s - found
> CMake Error at lib/CMakeLists.txt:34 (add_dependencies):
>  add_dependencies called with incorrect number of arguments
> 
> 
> -- Found PythonInterp: /usr/bin/python2.7
> -- Configuring incomplete, errors occurred!
> 
> 
> So I am stuck, can someone help ?
> 
> Thank you
> 
> François
> 
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev



More information about the cfe-dev mailing list