title: What is __aeabi_unwind_cpp_pr1' and how can I avoid it?
body: <p>I have a bunch of arm assembly, C and C++ files. gcc is trying to link them, but these are for an embedded project. </p>
  
  <p>I am not using any external libraries, all code that is being used was written by me. An error seems to happen because I have a function called <code>int kernel_main(void)</code> defined in <code>main.c</code> that is trying to call <code>set_LED(int value)</code> defined in <code>mailbox.cpp</code> which includes the header <code>mailbox.h</code> (I did include the header in the main.c file).</p>
  
  <p>The exact error is:</p>
  
  <pre><code>undefined reference to `__aeabi_unwind_cpp_pr1'
  </code></pre>
  
  <p>The way I am making my project is:
  -compile all source files (.s, .c, .cpp) into object files (.o) without linking (-c), then link them all together with the use of a custom linker script.</p>
  
  <p>Edit: I am going to add some information to make things more clear.</p>
  
  <p>First changing all files so that all of them are C files (no cpp extensions) yields:</p>
  
  <pre><code>undefined reference to `set_LED'
  </code></pre>
  
  <p>It is unlikely that the issue itself is name mangling an it probably has nothing to do with CPP and C differences.</p>
  
  <p>The problem is very likely to be a linker issue</p>
  
  <p>This is the build process:</p>
  
  <p>Compile c files, Example: </p>
  
  <pre><code>arm-none-eabi-g++ -O0 -march=armv8-a source/MainFiles/mailbox.cpp -nostartfiles -c -o objects/MainFiles/mailbox.o
  </code></pre>
  
  <p>(Compiling a C++ file would be identical except for the use of g++ instead of gcc)</p>
  
  <p>Link everything:</p>
  
  <pre><code>arm-none-eabi-ld object1 object2... -o build/kernel.elf -T ./source/kernel.ld -I include_directory_1 -I include_directory_2 -L include_directory_1 -L indlude_directory_2
  </code></pre>
  
  <p>Include directories are all directories under the current one</p>
  
  <p>Edit:
  The error came back. Ignore the parts of this question relevant to name mangling. The error I need to fix is:</p>
  
  <pre><code>./objects/Hardware/mailbox.o:(.ARM.exidx+0x18): undefined reference to `__aeabi_unwind_cpp_pr1'
  </code></pre>
  
  <p>So far all I know is that this has something to do with unwinding the stack and exceptions. It seems the function is defined in libgcc. However I have used <code>-nostdlib</code>, I have omitted it, and in both cases the error persists. I have tried changing file extensions to .c whenever possible and to .cpp whenever possible, alas the error is always there.</p>
  
  <p>It got fixed only as long as I had exactly 1 cpp file and the rest of my files were C files (this is no longer true, I tried). What triggered the error again was that I was refactoring the code and I wanted to move a couple of functions to new files.</p>
  
  <p>In other words, without deleting a single file, declaring a function named <code>wait(uint32_t time)</code> in mailbox.cpp works, declaring it in a file called time.c (or cpp) with it's respective header declaration and including the header in mailbox.cpp breaks things. Note I don't delete the files when moving the function I simply delete the function declaration inside each file.</p>
  
  <p>Adding a stub like this:</p>
  
  <pre><code>void __aeabi_unwind_cpp_pr1()
  {
  
  }
  </code></pre>
  
  <p>Fixes the problem and the code works. But I don't like this solution. I don't want a useless stub being called mysteriously in my code. I don't need nor want this function in my current implementation, how can I tell the compiler or the linker that they are to omit whatever they are doing that requires this function?</p>