emacs as the c++ ide on the Ubuntu

<?xml version="1.0" encoding="utf-8"?> emacs as the c++ ide on the Ubuntu

emacs as the c++ ide on the Ubuntu

Install tools

If you don't already have g++, make, and gdb, install them:

sudo apt-get install g++ make gdb

Create files

Create a project directory:

mkdir hellworld

Create a source file helloworld/hello.cpp:

#include <iostream>

int main(void) 
{
   char greeting[] = "Hello World!";
   std::cout << greeting << std::endl;
   return 0;
}

Create a makefile helloworld/Makefile:

# Makefile for GNU g++

CC=g++
CFLAGS=-g -Wall
all: hello

hello: hello.cpp
    $(CC) $(CFLAGS) -o hello hello.cpp

clean:
    rm hello

Compile within Emacs

Open hello.cpp in Emacs

M-x compile RET

make -k RET

Run using Emacs shell

M-! ./hello RET

You should see the output in the minibuffer.

Debug with gdb in Emacs

For more information see: 32.6 Running Debuggers Under Emacs in the GNU Emacs manual.

To show multiple debugging windows such as breakpoints, locals, etc., set the gdb-many-windows variable in ~/.emacs:

(setq gdb-many-windows t)

Restart Emacs.

Start the debugger. While visiting helloworld/hello.cpp: M-x gdb RET --annotate=3 hello RET

Set a breakpoint by clicking in the left margin at the desired location.

Run the debugger by typing run at the (gdb) prompt in the gud-hello buffer.

In the GUD buffer, use the following commands:

C-c C-s Step into
C-c C-n Stev over
C-c C-p Evaluate the expression at point.
C-c C-r Continue
C-c C-u Continue until current line

When finished, type quit at the (gdb) prompt.

GDB quick reference

l => list
break 16 => breakpoint at line16
r => run
n => next
p i => print i
c => continue
q => quit
bt => check the function stack

http://darkdust.net/files/GDB%20Cheat%20Sheet.pdf


Post by: Jalen Wang (转载请注明出处)

转载于:https://www.cnblogs.com/jalenwang/archive/2013/05/07/3064817.html

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值