Skip to content

Instantly share code, notes, and snippets.

Last active October 17, 2023 02:35
Show Gist options
  • Save selfboot/f4943c0a09fe8b333df64f2098eeed16 to your computer and use it in GitHub Desktop.
Save selfboot/f4943c0a09fe8b333df64f2098eeed16 to your computer and use it in GitHub Desktop.
Suppose there is a main.cpp which depends on utils.cpp and static libraries static_A, and static libraries static_A depend on static libraries static_B, here static_A compile without -fno-omit-frame-pointer, but everything else with -fno-omit-frame-pointer, and the final generated binary, each static library and cpp Do functions in files have fr…
$ tree
├── main.cpp
├── Makefile
├── static_A
│   ├── static_A.cpp
│   └── static_A.h
├── static_B
│   ├── static_B.cpp
│   └── static_B.h
├── utils.cpp
└── utils.h
#include <iostream>
#include <thread>
#include <unistd.h>
#include "utils.h"
#include "static_A/static_A.h"
void function_entry(){
write(1, "Inside main function\n", 21);
int main() {
while (true) {
return 0;
# Makefile
all: main
main: main.o utils.o libstatic_A.a libstatic_B.a
g++ -fno-omit-frame-pointer main.o utils.o -L. -lstatic_A -lstatic_B -o main
main.o: main.cpp utils.h static_A/static_A.h static_B/static_B.h
g++ -fno-omit-frame-pointer -c main.cpp
utils.o: utils.cpp utils.h
g++ -fno-omit-frame-pointer -c utils.cpp
libstatic_A.a: static_A/static_A.o
ar rvs libstatic_A.a static_A/static_A.o
libstatic_B.a: static_B/static_B.o
ar rvs libstatic_B.a static_B/static_B.o
static_A/static_A.o: static_A/static_A.cpp static_A/static_A.h static_B/static_B.h
g++ -fno-omit-frame-pointer -I./static_B -c static_A/static_A.cpp -o static_A/static_A.o
static_B/static_B.o: static_B/static_B.cpp static_B/static_B.h
g++ -fno-omit-frame-pointer -c static_B/static_B.cpp -o static_B/static_B.o
rm -f *.o *.a main static_A/*.o static_B/*.o
#include <unistd.h>
#include <thread>
#include "static_B.h"
void printStaticA() {
#pragma once
void printStaticA();
#include <unistd.h>
#include <thread>
void printStaticB() {
#pragma once
void printStaticB();
#include <unistd.h>
#include <thread>
void printUtils() {
#pragma once
void printUtils();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment