PA Note
PA Note
Linux
#
$sudo apt update
#
$whereis <name>
Vim
0
line start, $
line end
/word
search "word", n
find next, N
find previous
d0
delete until line start, d$
delete until line end, dd
cut current line
y0
copy until line start, y$
copy until line end, yy
copy current line
p
paste register
u
undo, ctrl+r
redo
gcc
## ref
# https://www.cprogramming.com/gcc.html
# https://www3.ntu.edu.sg/home/ehchua/programming/cpp/gcc_make.html
## Syntax
#
-o outputfile
# enable all warnings
-Wall
# treat warnings as errors
-Werror
# to use by gdb
-g
## Process
# 1.pre-processing
# include headers and expands the macros
$cpp hello.c > hello.i
# 2.compilation
# compile into assembly code for a specific processor
$gcc -S hello.i
# 3.assembly
# convert into machine code
$as -o hello.o hello.s
# 4.linker
$ld -o hello hello.o ...libraries...
## Utilities
# display the type of object files and executable files
$file <filename>
# lists symbol table of object files
$nm <filename>
# examines an executable and displays a list of the shared libraries that it needs
$ldd <filename>
make
a makefile for hello.c
all: hello
hello: hello.o
gcc -o hello hello.o
hello.o: hello.c
gcc -c hello.c
clean:
rm hello.o hello
rules
target: pre-req-1 pre-req-2
command
Run the command if the target is out-dated compared with its pre-requisite.
Note that command must be preceded by a tab.
Note that start the target "all" when running make without argument.
Another version:
# define a macro
filename = hello
all: $(filename)
echo ALL DONE
$(filename): $(filename).o
gcc -o $(filename) $(filename).o
# $@ for the pattern-matched target
# $< for the pattern-matched dependency
%.o: %.c
gcc -o $@ -c $<
clean:
rm *.o $(filename)
gdb
# start
$gdb <executable name>
# show lines
$list
# set breakpoints
$break <source code line number>
# print variable
$print <var name to print>
# set variable's values
$set <var> = <value>
# watch a variable and pause when it is changed
$watch <var>
# run
$run
# continue
$continue
# hit <return> re-executes the last command
$<return>
# qiut
$quit