Home > Article > Backend Development > Why am I getting \"Undefined symbol ___gxx_personality_v0 on link\" errors when compiling my C code with gcc?
Undefined Symbol Errors During C Compilation
As you attempt to compile your C program using the command "gcc test.cpp," you encounter the error message "Undefined symbol ___gxx_personality_v0 on link." This error signifies a missing symbol required for successful linking.
The core issue stems from using the incorrect compiler for C code. While gcc is primarily intended for compiling C programs, C requires a distinct compiler such as g . When you employ gcc with C code, it lacks the necessary capability to recognize and handle the specific symbol ___gxx_personality_v0, which is essential for handling exceptions and unwinding.
To address this issue, there are two recommended approaches:
Using g Compiler
The primary solution is to use the appropriate compiler for C code. Replace gcc with g in your command line as follows:
g++ test.cpp
g is equipped to handle the complexities of C , including the necessary symbols required for linking.
Linking with C Standard Library (Overriding Approach)
Alternatively, if you have a compelling reason to continue using gcc, you can add the option "-lstdc " to your command line. This option instructs gcc to link against the C standard library, which contains the missing symbol:
gcc test.cpp -lstdc++
Using this method, you can still compile and link your C code with gcc, but it may not be as efficient or recommended.
By adhering to these solutions, you can eliminate the "Undefined symbol ___gxx_personality_v0 on link" error and ensure successful compilation and linking of your C code.
The above is the detailed content of Why am I getting \"Undefined symbol ___gxx_personality_v0 on link\" errors when compiling my C code with gcc?. For more information, please follow other related articles on the PHP Chinese website!