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:
# 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. |