Reputation: 2208
I've installed clang++-5.0 to try out new C++17 features, but to get the full experience I need a new library. After being unable to find newer libstdc++, I decided to try out libc++.
I've checked it out using similar way described here.
After checkout, I've compiled it with clang itself, since it was advised to use clang. Compilation went without problems. Then I installed it, make put them in the /usr/local/include/c++/v1
directory.
When I tried to compile anything, I was getting an error saying the compiler couldn't find <stddef.h>
. I solved the problem with "redirecting" the includes: -isystem /usr/local/include/c++/v1
.
But then linker throws a lot of errors related to exceptions and virtual tables. I have no idea what to do in this case.
Is it possible to fix it?
My setup: ubuntu 16.04 LTS with all updates, clang++-5.0, cmake-3.6 .
Here are my flags:
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -v -stdlib=libc++ -Wall -Wextra -pedantic-errors -std=c++1z -isystem /usr/local/include/c++/v1")
Excerpt from error messages:
//usr/local/lib/libc++.so: undefined reference to `__cxa_end_catch'
//usr/local/lib/libc++.so: undefined reference to `__cxa_pure_virtual'
//usr/local/lib/libc++.so: undefined reference to `__cxa_rethrow'
//usr/local/lib/libc++.so: undefined reference to `vtable for __cxxabiv1::__si_class_type_info'
//usr/local/lib/libc++.so: undefined reference to `vtable for __cxxabiv1::__class_type_info'
//usr/local/lib/libc++.so: undefined reference to `vtable for __cxxabiv1::__vmi_class_type_info'
UPDATE:
After building libc++abi it successfully passes build step, though now it crashes with error saying
error while loading shared libraries: libc++abi.so.1: cannot open shared object file: No such file or directory
Current flags:
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -isystem /usr/local/include/c++/v1 -stdlib=libc++ -lc++abi -Wall -Wextra -pedantic-errors -std=c++1z")
After having a look, I found that they are absent in /usr/lib/
, but are present in /usr/local/lib
.
Here is the output of ldd program
:
linux-vdso.so.1 => (0x00007ffd1b7da000)
libc++abi.so.1 => /usr/local/lib/libc++abi.so.1 (0x00007f69bd322000)
libc++.so.1 => /usr/local/lib/libc++.so.1 (0x00007f69bcf80000)
libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f69bcc76000)
libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007f69bca60000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f69bc697000)
libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f69bc479000)
librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1 (0x00007f69bc271000) /lib64/ld-linux-x86-64.so.2 (0x000055e63a9a9000)
Upvotes: 2
Views: 6717
Reputation: 2208
So what lead to problem was actually me leaving the part with libc++abi. Most of the procedure is as specified in the docs, with minor deviation.
The procedure for me was roughly as following:
Checkout llvm
Checkout libc++ and libc++abi. Remember to checkout both!
Configure. I'm not sure if it matters, but I builded it with release configuration, e.g. specified -DCMAKE_BUILD_TYPE=Release
. Also, make sure that it will be compiled with clang itself.
Install both. They will probably be somewhere around /usr/local/lib/
folder.
Let compiler know that you want libc++. The flags are -stdlib=libc++ -lc++abi
. If it will complain about missing <stddef.h>
, add -isystem path/to/includes/
to the compiler flags, which in my case was -isystem /usr/local/include/c++/v1
.
Upvotes: 2