Code Yarns ‍👨‍💻
Tech BlogPersonal Blog

Undefined reference error with cxa_free_exception

📅 2014-May-02 ⬩ ✍️ Ashwin Nanjappa ⬩ 📚 Archive


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/ 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.


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:


Tried with: GCC 4.8.2, CMake and Ubuntu 14.04