Trying to build libcxx/libcxxabi on Linux 64 bit

Hello. I am interested in testing my C++ programs against libcxx build
on Linux with libcxxabi, mostly to see if using a different toolchain
than the GCC/libstdc++ would find out any bugs in my software. I am
running Kubuntu Raring 64 bit and my system's clang is 3.2, g++ and
libstdc++-4.8-dev is 4.8.1.

I have checked-out the libcxx and libcxxabi SVN. From
http://libcxx.llvm.org/ I read the following instructions:

"""Build on Linux using CMake and libc++abi.
You will need to keep the source tree of libc++abi available on your
build machine and your copy of the libc++abi shared library must be
placed where your linker will find it."""

So I go to the libcxxabi directory. There is no README.txt or
INSTALL.txt file to tell me how to build the "copy of the libc++abi
shared library", but I see a script buildit under <tree-root>/lib.
However upon executing it I get the following errors:

$ ./buildit
+ clang++ -c -g -O3 -fPIC -std=c++11 -stdlib=libc++ -fstrict-aliasing
-Wstrict-aliasing=2 -Wsign-conversion -Wshadow -Wconversion
-Wunused-variable -Wmissing-field-initializers -Wchar-subscripts
-Wmismatched-tags -Wmissing-braces -Wshorten-64-to-32 -Wsign-compare
-Wstrict-aliasing=2 -Wstrict-overflow=4 -Wunused-parameter
-Wnewline-eof -I../include ../src/abort_message.cpp
+ clang++ -c -g -O3 -fPIC -std=c++11 -stdlib=libc++ -fstrict-aliasing
-Wstrict-aliasing=2 -Wsign-conversion -Wshadow -Wconversion
-Wunused-variable -Wmissing-field-initializers -Wchar-subscripts
-Wmismatched-tags -Wmissing-braces -Wshorten-64-to-32 -Wsign-compare
-Wstrict-aliasing=2 -Wstrict-overflow=4 -Wunused-parameter
-Wnewline-eof -I../include ../src/cxa_aux_runtime.cpp
../src/cxa_aux_runtime.cpp:14:10: fatal error: 'typeinfo' file not found
#include <typeinfo>
         ^
1 error generated.

Please help me do the build correctly. Thank you.

Hello -- so I noticed that the below command seems to expect libc++ to
pre-exist on the system:

+ clang++ -c -g -O3 -fPIC -std=c++11 -stdlib=libc++ -fstrict-aliasing
-Wstrict-aliasing=2 -Wsign-conversion -Wshadow -Wconversion
-Wunused-variable -Wmissing-field-initializers -Wchar-subscripts
-Wmismatched-tags -Wmissing-braces -Wshorten-64-to-32 -Wsign-compare
-Wstrict-aliasing=2 -Wstrict-overflow=4 -Wunused-parameter
-Wnewline-eof -I../include ../src/cxa_aux_runtime.cpp
../src/cxa_aux_runtime.cpp:14:10: fatal error: 'typeinfo' file not found
#include <typeinfo>
         ^
1 error generated.

... whereas I am trying to compile libcxxabi *before* libcxx so that I
can build libcxx *based* on libcxxabi so this cyclic dependency is
going nowhere. So I compiled libcxx on libsupcxx without any problems
and installed it and then tried again to compile libcxxabi. Now I get:

clang++ -c -g -O3 -fPIC -std=c++11 -stdlib=libc++ -fstrict-aliasing
-Wstrict-aliasing=2 -Wsign-conversion -Wshadow -Wconversion
-Wunused-variable -Wmissing-field-initializers -Wchar-subscripts
-Wmismatched-tags -Wmissing-braces -Wshorten-64-to-32 -Wsign-compare
-Wstrict-aliasing=2 -Wstrict-overflow=4 -Wunused-parameter
-Wnewline-eof -I../include ../src/cxa_default_handlers.cpp
In file included from ../src/cxa_default_handlers.cpp:18:
../src/cxa_exception.hpp:66:9: error: unknown type name '_Unwind_Exception'
        _Unwind_Exception unwindHeader;
        ^
../src/cxa_exception.hpp:100:9: error: unknown type name '_Unwind_Exception'
        _Unwind_Exception unwindHeader;
        ^
../src/cxa_default_handlers.cpp:35:13: error: unknown type name
'_Unwind_Exception'
            _Unwind_Exception* unwind_exception =
            ^
../src/cxa_default_handlers.cpp:36:34: error: unknown type name
'_Unwind_Exception'
                reinterpret_cast<_Unwind_Exception*>(exception_header + 1) - 1;
                                 ^
Please help. Thank you.

BTW I just also noticed the following error in libcxx/include/list line 1603:

list<_Tp, _Alloc>::pop_back()
{
    _LIBCPP_ASSERT(!empty(), "list::pop_front() called with empty list");

pop_front should read pop_back

libc++abi only depends on libc++'s headers. Install the libc++
headers, build libc++abi, then build libc++.

Fixed in r184691, thanks!

Dmitri

Thanks Matthew and Dmitri for your replies.

libc++abi only depends on libc++'s headers. Install the libc++
headers, build libc++abi, then build libc++.

This is strange -- please add that in some readme file or something.

[I'm not a libc++/libc++abi developer.]

Anyhow, as I said I compiled libcxx once against libsupcxx and
installed it, and then trying to compile libcxxabi I got the """error:
unknown type name '_Unwind_Exception'""" error which I reported above.
Please see my previous post about this and kindly help me resolve that
problem.

You probably need to install unwind.h from either libgcc or libunwind.
It looks like Clang's builtin <unwind.h> header is pretty incomplete,
and doesn't provide _Unwind_Exception.

Perhaps file a bug against Clang asking that
clang/lib/Headers/unwind.h should be made more complete with regard to
the Linux Standard Base.

Hi thank you for your reply -- installing the libunwind8-dev on my
Kubuntu Raring system fixed the compilation of libcxxabi. I have now
copied the libc++abi.so to my /usr/lib.

Now I once more try to compile libc++ using libc++abi (previously I
used libsupc++):

I have my libcxx and libcxxabi SVN repos under: ~/sr/_repos/svn/

[samjnaa:~/sr/_repos/svn/libcxx/build] CC=clang CXX=clang++ cmake -G
"Unix Makefiles" -DLIBCXX_CXX_ABI=libcxxabi
-DLIBCXX_LIBCXXABI_INCLUDE_PATHS=../../libcxxabi/include/
-DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/usr ..
...
CMake Error at CMakeLists.txt:118 (message):
  Failed to find cxa_demangle.h
Call Stack (most recent call first):
  CMakeLists.txt:140 (setup_abi_lib)

There is no cxa_demangle.h in the libcxxabi source tree! What to do!?

That's a bug in libc++'s CMakeLists.txt: libc++abi no longer provides
cxa_demangle.h (http://llvm.org/viewvc/llvm-project?view=revision&revision=184118),
so libc++ shouldn't be checking for it anymore. On line 141, change
"cxxabi.h;cxa_demangle.h" to just "cxxabi.h".

Hmm -- there seems to *have been* such a file in that location:

https://llvm.org/viewvc/llvm-project/libcxxabi/trunk/include/?pathrev=146677

but one does not exist *now*:

https://llvm.org/viewvc/llvm-project/libcxxabi/trunk/include/

Help please?!

Hello thank you very much for your help. I did that and the compiling
went on fine but failed at the last stage of linking:

Linking CXX shared library libc++.so
/usr/bin/ld: error: cannot find -lc++abi
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [lib/libc++.so.1.0] Error 1
make[1]: *** [lib/CMakeFiles/cxx.dir/all] Error 2
make: *** [all] Error 2

The libcxxabi buildit script had only produced libc++abi.so.1.0 so
that is what I copied to /usr/lib, but now apparently I have to
manually produce the symlink of this file to libc++abi.so without the
versioning and doing that fixed the problem.

Thank you very much. I hope the libcxx developers fix the problem with
the CMakeLists.txt and the libcxxabi developers add a small README
note saying libunwind-dev may need to be installed. (I am not
knowledgeable enough about compiler internals to know whether it is
the place of Clang to provide all the functionality that libunwind
does so I'm not filing the bug you suggested. Since obviously you know
more than me, perhaps you should file it!)

Sorry for the multiple mails. I forgot to ask one more thing:

I have now successfully compiled and linked libcxx against all three
of libsupcxx, libcxxabi and libcxxrt. Any suggestions on which one I
should actually use with clang? I seem to have read somewhere that
clang is setup to libsupcxx by default for compatibility with GCC or
something like that? So would it be preferable to use the version
built against libsupcxx?

Interfacewise, libsupc++, libc++abi, and libcxxrt are all equivalent (or
should be).

License-wise, libc++abi and libcxxrt are BSD-like, while libsupc++ is GPL
with runtime exception.

libcxxrt is slightly easier to bootstrap because it's self-contained C/C++
code depending only on the C standard library, whereas libc++abi is a bit
funny because it in turn depends on some C++ library headers.

libcxxrt is smaller than libc++abi, but libc++abi's symbol demangler is
more spec compliant than libcxxrt's. (In fairness, libcxxrt's demangler is
mostly taken from libelftc, and the libcxxrt developers intend to
improve/replace it.)

Both libc++abi and libcxxrt's developers have been very responsive to
reported issues.

Hi all,
I'm trying to compile libc++ and I'm running into some of the problems as below:

I have checked-out the libcxx and libcxxabi SVN. From
http://libcxx.llvm.org/ I read the following instructions:

"""Build on Linux using CMake and libc++abi.
You will need to keep the source tree of libc++abi available on your
build machine and your copy of the libc++abi shared library must be
placed where your linker will find it."""

So I have to build libc++abi for libc++

So I go to the libcxxabi directory. There is no README.txt or
INSTALL.txt file to tell me how to build the "copy of the libc++abi
shared library", but I see a script buildit under <tree-root>/lib.
However upon executing it I get the following errors:

$ ./buildit
+ clang++ -c -g -O3 -fPIC -std=c++11 -stdlib=libc++ -fstrict-aliasing
-Wstrict-aliasing=2 -Wsign-conversion -Wshadow -Wconversion
-Wunused-variable -Wmissing-field-initializers -Wchar-subscripts
-Wmismatched-tags -Wmissing-braces -Wshorten-64-to-32 -Wsign-compare
-Wstrict-aliasing=2 -Wstrict-overflow=4 -Wunused-parameter
-Wnewline-eof -I../include ../src/abort_message.cpp
+ clang++ -c -g -O3 -fPIC -std=c++11 -stdlib=libc++ -fstrict-aliasing
-Wstrict-aliasing=2 -Wsign-conversion -Wshadow -Wconversion
-Wunused-variable -Wmissing-field-initializers -Wchar-subscripts
-Wmismatched-tags -Wmissing-braces -Wshorten-64-to-32 -Wsign-compare
-Wstrict-aliasing=2 -Wstrict-overflow=4 -Wunused-parameter
-Wnewline-eof -I../include ../src/cxa_aux_runtime.cpp
../src/cxa_aux_runtime.cpp:14:10: fatal error: 'typeinfo' file not found
#include <typeinfo>
         ^
1 error generated.

This can be fixed by editing the "buildit" script and adding
-I../../libcxx/include

However, the build fails at linking:

clang++ abort_message.o cxa_aux_runtime.o cxa_default_handlers.o
cxa_demangle.o cxa_exception.o cxa_exception_storage.o cxa_guard.o
cxa_handlers.o cxa_new_delete.o cxa_personality.o cxa_unexpected.o
cxa_vector.o cxa_virtual.o exception.o private_typeinfo.o stdexcept.o
typeinfo.o -fPIC -o libc++abi.so.1.0 -shared -nodefaultlibs
-Wl,-soname,libc++abi.so.1 -lpthread -lrt -lc -lstdc++ -std=c++11
-stdlib=libc++ -fstrict-aliasing -Wstrict-aliasing=2 -Wsign-conversion
-Wshadow -Wconversion -Wunused-variable -Wmissing-field-initializers
-Wchar-subscripts -Wmismatched-tags -Wmissing-braces
-Wshorten-64-to-32 -Wsign-compare -Wstrict-aliasing=2
-Wstrict-overflow=4 -Wunused-parameter -Wnewline-eof
/usr/bin/ld: error: cannot find -lc++

There seems to be a circular dependency: libc++abi depends on libc++,
but I'm trying to build libc++abi for use by libc++ :frowning:

Or do I have to build libsupc++ so I can build libc++ so I can build
libc++abi so I can build libc++ ?

Csaba