Home > Article > Backend Development > Why Do I Get the \'Undefined Symbol \'___gxx_personality_v0\'\' Error When Compiling C Code with GCC?
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!