Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

undefined reference to `__gxx_personality_sj0`

With gcc 4.6 when trying to execute this code:

   #include <iostream>

using namespace std;

#include <bitset>

int main()
{
   //Int<> a;
   long long min = std::numeric_limits<int>::min();
   unsigned long long max = std::numeric_limits<int>::max();
   cout << "min: " << min << '\n';
   cout << "max: " << max << '\n';
   cout << (min <= max);
   std::bitset<64> minimal(min);
   cout << "minimal: " << minimal;

   return 0;
}

I'm getting the following error:
1. undefined reference to __gxx_personality_sj
2. undefined reference to _Unwind_SjLj_Register
3. undefined reference to _Unwind_SjLj_Unregister
4. undefined reference to _Unwind_SjLj_Resume

What on hell is going on?!

like image 544
smallB Avatar asked Oct 13 '11 08:10

smallB


3 Answers

These functions are part of the C++ exception handling support for GCC. GCC supports two kinds of exception handling, one which is based on calls to setjmp and longjmp (sjlj exception handling), and another which is based on the DWARF debugging info format (DW2 exception handling).

These sorts of linker errors will occur is you try to mix objects that were compiled with different exception handling implementations in a single executable. It appears that you are using a DW2 GCC, but some library that you are attempting to use was compiled with a sjlj version of GCC, leading to these errors.

The short answer is that these sorts of problems are caused by ABI incompatibilities between different compilers, and so occur when you mix libraries compiled with different compilers, or use incompatible versions of the same compiler.

like image 71
Mankarse Avatar answered Oct 24 '22 05:10

Mankarse


as smallB noted in a comment, you may have used gcc, focused on C programs, but you had a C++ program.

To compile a C++ program, make sure to use the g++ compiler driver instead!

example:

BAD: gcc -o foo.exe foo.cpp

GOOD: g++-o foo.exe foo.cpp

like image 43
n611x007 Avatar answered Oct 24 '22 04:10

n611x007


Just in case anyone else has this problem: I changed compilers AFTER creating .o files for my project.

When I rebuilt the same project, the new compiler didn't build new .o files, so they were missing some key info. After deleting the old files and rebuilding, the error was fixed.

I assume rebuilding from scratch, without the delete, would work the same.

like image 30
Ben Avatar answered Oct 24 '22 06:10

Ben