Skip to content

Instantly share code, notes, and snippets.

@pjhades
Last active August 29, 2019 13:17
Show Gist options
  • Save pjhades/e41a128aa68d8dddabdf218d9162e4a0 to your computer and use it in GitHub Desktop.
Save pjhades/e41a128aa68d8dddabdf218d9162e4a0 to your computer and use it in GitHub Desktop.
f
#include "libbar.h"
int main() {
bar();
return 0;
}
#include <stdio.h>
#include "libbaz.h"
void bar() {
printf("bar\n");
baz();
}
void bar();
#include <math.h>
#include <stdio.h>
void baz() {
printf("baz, sin(pi/2)=%lf\n", sin(M_PI / 2.0));
}
void baz();
all: libbaz.so libbar.so foo
# libbaz depends on libm
libbaz.so: libbaz.h libbaz.c
gcc -o $@ -shared -fPIC -lm $^
# libbar depends on libbaz
libbar.so: libbar.h libbar.c
gcc -o $@ -L. -Wl,-rpath=. -lbaz -shared -fPIC $^
# foo depends on libbar
foo: foo.c
gcc -o $@ -L. -Wl,-rpath=. -lbar $^
.PHONY: clean
clean:
rm -f libbaz.so libbar.so foo
diff --git a/Makefile b/Makefile
index 2d20a1c..d7a6bf3 100644
--- a/Makefile
+++ b/Makefile
@@ -11,7 +11,12 @@ CXXFLAGS := $(CXXFLAGS) -Wall -Werror -Wextra -fPIC
MODULE_NAME := netkit
INCLUDE :=
-LIBS := ./deps/logger/liblogger.a ./deps/threadpool/cpp/libthreadpool.a -lpthread
+LDFLAGS := -L./deps/logger \
+ -L./deps/threadpool/cpp \
+ -Wl,-rpath=./deps/logger \
+ -Wl,-rpath=./deps/threadpool/cpp \
+ -llogger \
+ -lthreadpool
OBJS := $(patsubst %.cpp, %.o, $(wildcard *.cpp))
@@ -33,7 +38,7 @@ lib$(MODULE_NAME).a: $(OBJS) | pre-process
$(AR) rc $@ $^
lib$(MODULE_NAME).so: $(OBJS) | pre-process
- $(CXX) -shared -o $@ $^ $(LIBS)
+ $(CXX) -shared -o $@ $(LDFLAGS) $^
.cpp.o:
$(CXX) $(CXXFLAGS) $(INCLUDE) -c $< -o $@
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment