-
Notifications
You must be signed in to change notification settings - Fork 0
/
make-correct.sh
executable file
·25 lines (20 loc) · 976 Bytes
/
make-correct.sh
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
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
echo Create directories.
mkdir -p -v obj
mkdir -p -v lib/dir/sub
mkdir -p -v run
echo Build bar.so:
g++ -c -o obj/bar.o src/bar.cpp -fPIC
g++ -shared -o lib/dir/sub/libbar.so obj/bar.o -Wl,-soname,libbar.so
echo Build foo.so:
g++ -c -o obj/foo.o src/foo.cpp -fPIC
# here, rpath is for finding libbar at runtime. at compile time, it's found through -L.
g++ -shared -o lib/dir/libfoo.so obj/foo.o -Wl,-soname,libfoo.so -Wl,-rpath,'$ORIGIN/sub' -Llib/dir/sub -lbar
### Alternate foo that doesn't link to bar:
#g++ -c -o obj/foo2.o src/foo2.cpp -fPIC
#g++ -shared -o lib/dir/foo.so obj/foo2.o -Wl,-soname,foo.so
echo Build main.run:
g++ -c -o obj/main.o src/main.cpp
# here, rpath is for finding libfoo in runtime, and rpath-link is to find libbar in compile time.
# libfoo is found through -L in compile time.
g++ -o run/main.run obj/main.o -Llib/dir -lfoo -Wl,-rpath-link,lib/dir/sub -Wl,-rpath,'$ORIGIN/../lib/dir'