-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathcompile
More file actions
executable file
·52 lines (40 loc) · 1.66 KB
/
compile
File metadata and controls
executable file
·52 lines (40 loc) · 1.66 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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#! /bin/sh
set -e
# -----------------------------------------------------------------------
# C++ usage:
# Compile stacktrace as a regular C++ program
echo "Compiling stacktrace.cpp"
g++ -fPIC -g -o stacktrace.o -c stacktrace.cpp
# Use it in your C++
echo "Compiling test1.cpp"
g++ -fPIC -g -o test1.o -c test1.cpp
# And link, using C++
echo "Linking test1"
g++ -o test1 test1.o stacktrace.o -lbfd -liberty
# -----------------------------------------------------------------------
# C Usage (linking with C++)
# For C, first compile a tiny C wrapper using a C++ compiler
echo "Compiling C wrappers to stacktrace.cpp"
g++ -fPIC -g -o c_stacktrace.o -c c_stacktrace.cpp
# Compile your C code using C compiler
echo "Compiling test2.c"
gcc -fPIC -g -o test2.o -c test2.c
# Link everything together using C++ compiler (you *need* to use C++ for
# linking, because stacktrace.o depends on bunch of C++ runtime that only g++
# knows how to link properly)
echo "Linking test2"
g++ -o test2 test2.o stacktrace.o c_stacktrace.o -lbfd -liberty
# -----------------------------------------------------------------------
# C Usage (linking with C, using a shared library)
# For C, first compile a tiny C wrapper using a C++ compiler
echo "Compiling C wrappers to stacktrace.cpp"
g++ -fPIC -g -o c_stacktrace.o -c c_stacktrace.cpp
# Create a shared library (that contains all the C++ runtime) using a C++
# compiler:
g++ -shared -o libstacktrace.so stacktrace.o c_stacktrace.o -lbfd -liberty
# Compile your C code using C compiler
echo "Compiling test2.c"
gcc -fPIC -g -o test2.o -c test2.c
# Link test2 using C compiler
echo "Linking test2shared"
gcc -o test2shared test2.o -L. -lstacktrace -Wl,-rpath=.