Specify the GCC-O output file for common Emacs configurations

Source: Internet
Author: User

The shortcut keys for compiling with GCC/g ++ are configured in section 6th of "organization and use of common Emacs configurations", as shown below:

 
(Defun quick-compile () "A quick compile funciton for C" (interactive) (compile (Concat "GCC" (buffer-Name (current-buffer )) "-g-PG"); compile C (Global-set-Key [(F5)] 'quick-compile); shortcut: F5

The GCC/g ++-O output parameter is not specified. If you want to make the parameter consistent with the file name opened by the current buffer, you can set it as follows:

 
(Defun quick-compile () "A quick compile funciton for C" (interactive) (compile (Concat "GCC" (buffer-Name (current-buffer )) "-g-PG-o" (file-name-sans-extension (buffer-Name (current-buffer ))))));; compile C (Global-set-Key [(F5)] 'quick-compile); shortcut: F5

(File-name-sans-extension (buffer-Name (current-buffer) is used to obtain the file name of the current buffer (remove the extension)

As shown in:

You must modify the shortcut settings for GDB debugging as follows:

(Defun quick-Debug () "A quick debug funciton for C ++" (interactive); (GDB (Concat "GDB -- annotate = 3" ". out ")));; debugging (GDB (Concat "GDB -- annotate = 3" (file-name-sans-extension (buffer-Name (current-buffer ))))));; debug (Global-set-Key [(F6)] 'quick-Debug); shortcut: F6

Note: "GDB -- annotate = 3" must be added with a space to separate it from the following parameters.

Open the file to be debugged and press the F6 shortcut. GDB will automatically load the file associated with the current buffer. Of course, you can also use the following command in the existing GDB debugging window, to load the file to be debugged:

 
(GDB) file 6.1

The display effect is as follows:

Note:

If you use the. emacs configuration file provided in "common Emacs configuration arrangement and use", you need to make some modifications and comment out the following configurations. Otherwise, GDB multi-window debugging may fail.

; Shell, after GDB exits, the buffer is automatically closed; (add-hook 'Shell-mode-hook' mode-hook-func );; (add-hook 'gdb-mode-hook' mode-hook-func) (defun mode-hook-func () (set-process-sentinel (get-buffer-process (current-buffer) # 'Kill-buffer-on-exit )) (defun kill-buffer-on-exit (process state) (message "% s" State) (if (or (string-match "exited abnormally with code. * "State) (string-match" finished "State) (kill-buffer (current-buffer ))))

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.