Error: Undefined reference to '_ gxx_personality_v0 ′

Source: Internet
Author: User


13:49:18 | category:

Default category | Tag:
| Large font size, medium/small subscription

1. Linux develop notes

* To compile the C ++ program, add-lstdc ++ sample: gcc-lstdc ++-O test. C. Otherwise, the "undefinedreference to '_ gxx_personality_v0'" error will be reported.

2. Alas, use the GCC command to compile the C program, and use the G ++ command to compile the C ++ program.

G ++ and GCC are essentially the same. In essence, GCC is used. All the C ++ programs in our lab are compiled with GCC, and the general program is enough with GCC. For C ++ programs, GCC or G ++ can be used during compilation. However, it is best to use g ++ for connection, because g ++ will automatically connect to the C ++ standard library. You can also use GCC to connect to the C ++ program, however, you need to manually connect to the C ++ standard library. Otherwise, undefined reference to '_ gxx_personality_v \ 0' will appear'
Errors.

It can be seen that lstdc ++ corresponds to the Standard C ++ library.

-

Write the following program in Linux:

Quote:
# Include
# Include
# Include
Int COUNT = 0;
Void ctrl_c_count (INT );
Main ()
{
Int C;
Void (* old_handler) (INT );
Old_handler = signal (SIGINT, ctrl_c_count );
While (C = getchar ()! = '\ N '))
;
Printf ("ctrl_c COUNT = % d \ n", count );
Signal (SIGINT, old_handler );

}
Void ctrl_c_count (int I)
{
Printf ("ctrl_c \ n ");
Count ++;
}



The function of this program is to study the application of the signal function.
The signal function is used to set the processing function of the semaphore to custom.
SIGINT is a semaphore generated when you press Ctrl + C on the terminal.
Its default processing function is to terminate a running process.
Now press Ctrl + C to add 1 to the global variable count.
The process ends when you press enter on the terminal.
And set the processing function of SIGINT to the default one.

When I save the above program as T. cpp
Using gcc-o t. cpp
The following error is returned:
/Tmp/ccgsoxh2.o (. eh_frame + 0x11): Undefined reference to '_ gxx_personality_v0'
Solution: Use gcc-o t. cpp-lstdc ++
Why does this error occur: it is because you use GCC to compile the. cpp file. By default, the. cpp file is in the C ++ file format.
Another method is to use g ++-o t. cpp.
Another way is to save the file in. c format, which is all C code.
Then gcc-o t. C or G ++-o t. c is OK.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.