# Compiling using clang with libc++, undefined abi references



## ybungalobill (Oct 26, 2013)

I'm running FreeBSD 9.2-RELEASE, installed the devel/libc++ port and tr*i*ed to compile the following program


```
#include <type_traits>

int main() {
	try { throw 0; } catch(int) {}
}
```
using `clang++ -stdlib=libc++ -I /usr/local/include/c++/v1 -L /usr/local/lib test.cpp`.

Note: I had to specify the include and library search paths because this is where devel/libc++ was installed, whereas clang searches the /usr/include/c++/v1 and /usr/lib by default.

I get the following link errors:

```
/tmp/test-oHEkZb.o: In function `main':
test.cpp:(.text+0xe): undefined reference to `__cxa_allocate_exception'
test.cpp:(.text+0x1b): undefined reference to `typeinfo for int'
test.cpp:(.text+0x23): undefined reference to `__cxa_throw'
test.cpp:(.text+0x4a): undefined reference to `__cxa_begin_catch'
test.cpp:(.text+0x54): undefined reference to `__cxa_end_catch'
[...]
```

I found this 2-year old question with a similar problem, albeit unrelated to FreeBSD. It mentions libc++abi library, which I couldn't find in the ports.

Is it possible to use clang with libc++? How?

Thanks.


----------



## ybungalobill (Oct 27, 2013)

OK, I could install libc++abi or libcxxrt manually, as described on the libc++ homepage. Hopefully it would work.

However, it happens that libc++ and libcxxrt are already distributed with FreeBSD, but just not built by default (on pre-10.0 systems). So, to my understanding, the "canonical" way is to install both from /usr/src, as described here:



> The new stack isnâ€™t installed by default, but building and installing it is very easy:
> 
> 
> ```
> ...



Now my code compiles and runs simply with `clang++ -stdlib=libc++ test.cpp`.


----------

