C++ linker presentation
This commit is contained in:
23
cpplinker/02_symbol_resolution/build.sh
Normal file
23
cpplinker/02_symbol_resolution/build.sh
Normal file
@@ -0,0 +1,23 @@
|
||||
#!/bin/bash
|
||||
set -e
|
||||
|
||||
echo "=== Compile to object files ==="
|
||||
g++ -std=c++17 -c math.cpp -o math.o
|
||||
g++ -std=c++17 -c main.cpp -o main.o
|
||||
|
||||
echo ""
|
||||
echo "=== math.o: exported symbols (demangled) ==="
|
||||
nm -C -g math.o
|
||||
|
||||
echo ""
|
||||
echo "=== main.o: unresolved (UNDEF) symbols ==="
|
||||
nm -C -u main.o
|
||||
|
||||
echo ""
|
||||
echo "=== main.o: full symbol table ==="
|
||||
objdump -t main.o
|
||||
|
||||
echo ""
|
||||
echo "=== Link and run ==="
|
||||
g++ math.o main.o -o app
|
||||
./app
|
||||
9
cpplinker/02_symbol_resolution/main.cpp
Normal file
9
cpplinker/02_symbol_resolution/main.cpp
Normal file
@@ -0,0 +1,9 @@
|
||||
#include <iostream>
|
||||
|
||||
double square(double);
|
||||
|
||||
int main() {
|
||||
double r = square(5.0);
|
||||
std::cout << "square(5.0) = " << r << "\n";
|
||||
return 0;
|
||||
}
|
||||
3
cpplinker/02_symbol_resolution/math.cpp
Normal file
3
cpplinker/02_symbol_resolution/math.cpp
Normal file
@@ -0,0 +1,3 @@
|
||||
#include <iostream>
|
||||
|
||||
double square(double x) { return x * x; }
|
||||
Reference in New Issue
Block a user