Home > Backend Development > C++ > body text

Why does linking a free-standing C program with gcc result in an undefined reference to `__gxx_personality_v0`?

Linda Hamilton
Release: 2024-11-20 14:17:13
Original
994 people have browsed it

Why does linking a free-standing C   program with gcc result in an undefined reference to `__gxx_personality_v0`?

When compiling and linking a free-standing C program using gcc, a linker error can occur due to an undefined reference to __gxx_personality_v0. To understand the purpose of this symbol, let's explore its role in the context of the error message you provided.

What is the role of __gxx_personality_v0?

The symbol __gxx_personality_v0 is utilized in the stack unwinding tables, which are visible in the assembly output of stack unwinding. According to the Itanium C ABI, it is referred to as the Personality Routine.

In the absence of exceptions, defining this symbol as a global NULL void pointer will "work" because no exceptions are being thrown. However, attempting to throw an exception will result in unexpected behavior.

Alternative solutions:

  • Disable exceptions using -fno-exceptions.
  • If RTTI is also not being used, add -fno-rtti.
  • For exception-using programs, compile with g instead of gcc, which automatically includes the necessary library (-lstdc ).

The above is the detailed content of Why does linking a free-standing C program with gcc result in an undefined reference to `__gxx_personality_v0`?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template