-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathMakefile
More file actions
29 lines (23 loc) · 1.28 KB
/
Makefile
File metadata and controls
29 lines (23 loc) · 1.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# WARN: in makefile we must use tab instead of spaces
all: run.exe
# -Werror will stop the compilation if warnnings reported
run.exe: inc/list.h inc/list.c example.c
gcc -o run.exe -g -Wall -std=c99 inc/list.c example.c -I./inc/ -lm
#gcc -o run.exe -O2 -Wall -std=c99 -I./inc/ inc/list.c example.c -lm
lib:
gcc -o inc/list.o -g -Wall -c -std=c99 inc/list.c
ar crv inc/liblist.a inc/list.o
#to produce segment-independent code
gcc -o inc/liblist.so -g -Wall --shared -fPIC inc/list.c
#-fPIC always works(but may generate larger file), but -fpic may fail on some platforms
#gcc -o inc/liblist.so -Wall --shared -fpic inc/list.c
#gcc -o run.exe -Wall -std=c99 example.c -I./inc -L./inc -lm -llist
#gcc -o run.exe -Wall -std=c99 example.c -I./inc -L./inc -lm -llist -Wl,--rpath=./inc/
gcc -o run.exe -g -Wall -std=c99 example.c -I./inc -L./inc -lm -llist -Wl,--rpath=./inc/,--enable-new-dtags
# To run the run.exe generated by commands above, the ld.so path must be modified via LD_LIBRARY_PATH or /etc/ld.so.cache
# (in current directory, it will work even no setting; but in other directories, it fails)
# An example to use dlopen/dlclose
gcc -rdynamic -std=c99 -o run.exe -I./inc testdl.c -ldl -lm
.PHONY: clean
clean:
rm -f *.out *.exe *.o vgcore.* *.txt inc/*.{so,a,i,s,o} *.{so,a,i,s,o}