Undefined reference error with __cxa_free_exception@@CXXABI_1.3

Problem

I was compiling some C++ and CUDA code using CMake on Ubuntu 14.04. The linking stage threw up this error:

/usr/bin/ld: foobar.cpp.o: undefined reference to symbol '__cxa_free_exception@@CXXABI_1.3'
//usr/lib/x86_64-linux-gnu/libstdc++.so.6: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status

I had used these same source and CMake files without any compile error on a Ubuntu 12.04 system.

Solution

Ubuntu 14.04 uses newer versions of the GCC compilers and libraries. The hint here is that its complaining about a core C++ symbol: __cxa_free_exception. Suggesting the linker to link with the standard C++ library fixed this error. You can do this by adding -lstdc++ to the linker invocation.

For my CMake, I did this by adding -lstdc++ to the linking options to the target as:

target_link_libraries(
    foobar
    -lsomelibrary
    -lstdc++
    )

Tried with: GCC 4.8.2, CMake 2.8.12.2 and Ubuntu 14.04

2 thoughts on “Undefined reference error with __cxa_free_exception@@CXXABI_1.3

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.