1

I'm trying to use exceptions in a C++ code that runs on raspberry-pi zero. When I link the code dynamically it works fine. However, when I link it statically, I get:

terminate called after throwing an instance of 'std::exception'
terminate called recursively
Aborted

An example code to reproduce the problem:

#include <exception>
#include <stdio.h>

void foo(void)  
{  
    throw std::exception();  
}  

int main (void)  
{  
    try  
    {  
        foo();  
    }  
    catch(...)  
    {  
        printf("caught an exception\n");  
    }  

    return (0);  
}

My "problematic" link command is: g++ exceptionTest.cpp -o exceptionTest.out --static

Why does the static linking disrupts the exceptions mechanism?
Is there something I could do in my link command (e.g. add flags) to fix this?

Note: my problem appears very similar to GCC arm-none-eabi (Codesourcery) and C++ Exceptions but the OP there worked on a different system and the suggested solution was related to a link script (which I don't use).

Tal Ben-Porath
  • 135
  • 1
  • 5

0 Answers0