Home  >  Article  >  Backend Development  >  Why Do I Get the \'Undefined Symbol \'___gxx_personality_v0\'\' Error When Compiling C Code with GCC?

Why Do I Get the \'Undefined Symbol \'___gxx_personality_v0\'\' Error When Compiling C Code with GCC?

Linda Hamilton
Linda HamiltonOriginal
2024-11-23 13:09:11586browse

Why Do I Get the

Undefined Symbol "___gxx_personality_v0" in GCC Builds

When compiling C code with the command line gcc test.cpp, developers may encounter the error:

Undefined symbols:
  "___gxx_personality_v0", referenced from:
  etc...

This error occurs because gcc is intended for compiling C code. To build C code, use the C compiler g instead:

g++ test.cpp

Alternatively, if gcc must be used, add the -lstdc flag to the command line:

gcc test.cpp -lstdc++

This flag links the Standard C Library, which contains the necessary symbols.

Running md5 on the resulting executables (.a.out) from both g and gcc with -lstdc yields identical output, indicating that they are equivalent.

Therefore, using g is generally recommended for compiling C code for simplicity and compatibility.

The above is the detailed content of Why Do I Get the \'Undefined Symbol \'___gxx_personality_v0\'\' Error When Compiling C Code with GCC?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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