Home > Backend Development > C++ > Why am I getting an \'Undefined Symbol ___gxx_personality_v0\' error during compilation?

Why am I getting an \'Undefined Symbol ___gxx_personality_v0\' error during compilation?

Mary-Kate Olsen
Release: 2024-11-15 17:48:02
Original
1025 people have browsed it

Why am I getting an

Debugging "Undefined Symbol ___gxx_personality_v0" Error During Compilation

Problem:

While building C code using the command line, you encounter an undefined symbol error:

$ gcc test.cpp
Undefined symbols:
  "___gxx_personality_v0", referenced from:
Copy after login

Despite the simplicity of the code, it fails to compile without an explanation.

Explanation:

The error occurs because the code is being compiled using gcc, a compiler for C language, rather than g , the compiler for C . The symbol ___gxx_personality_v0 is a symbol specific to the C standard library (libstdc ), and it is not present in the C standard library (libc).

Solution:

There are two solutions to resolve this issue:

  • Use g :

    Since the code is written in C , it should be compiled using g , which includes both the C compiler and the C standard library. Use this command instead:

    $ g++ test.cpp
    Copy after login
  • Add the C Standard Library:

    If you need to use gcc, you can add the C standard library by adding the -lstdc flag to the command line. This flag instructs the linker to include the libstdc library, which contains the necessary symbols. Use this command instead:

    $ gcc test.cpp -lstdc++
    Copy after login

Note:

Using g is the preferred method as it handles both C and C code seamlessly. By choosing the correct compiler for the language you are using, you can prevent these types of errors and ensure successful compilation.

The above is the detailed content of Why am I getting an \'Undefined Symbol ___gxx_personality_v0\' error during compilation?. 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