Compiling using clang with libc++, undefined abi references

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

Code:
#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:
Code:
/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.
 
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:

Code:
# cd /usr/src/lib/libcxxrt
# make
# make install
# cd ../libc++
# make CXX=clang++
# make install

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