Created
September 10, 2023 15:17
-
-
Save fzakaria/3a043e67c1f9523835f4674e48abe9fc to your computer and use it in GitHub Desktop.
Playing with symbols
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
all: exe | |
# This library depends libx2.so soname and calls h() from it | |
y/liby.so: x/libx2.so | |
@mkdir -p $(dir $@) | |
echo 'extern int foo(); int g() { return foo(); }' | $(CC) -o $@ -shared -x c - -Lx -l:libx2.so '-Wl,--no-as-needed,--enable-new-dtags,-rpath,$$ORIGIN/../x' | |
# This library has both file and soname libx.so | |
x/libx.so: | |
@mkdir -p $(dir $@) | |
echo 'int foo(){return 12;}' | $(CC) -o $@ -shared -x c - | |
# This library has both file and soname libx.so | |
x/libx2.so: | |
@mkdir -p $(dir $@) | |
echo 'int foo(){return 1000;}' | $(CC) -o $@ -shared -x c - | |
# This links to b/liby.so and c/libx.so, and gets libx.so and liby.so in DT_NEEDED, no paths. | |
exe: y/liby.so x/libx.so | |
echo 'extern int g(); extern int foo(); int main(){ printf("\%d\n", g() + foo()); }' | \ | |
$(CC) -o $@ -include stdio.h -x c - -Ly -Lx -l:liby.so '-Wl,--no-as-needed,--enable-new-dtags,-rpath,$$ORIGIN/y' \ | |
-l:libx.so '-Wl,--no-as-needed,--enable-new-dtags,-rpath,$$ORIGIN/x' | |
clean: | |
rm -rf -- x y exe |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment