Last active
November 13, 2018 16:15
-
-
Save mattn/5770645ef52c69584046a1f9ffa6259a to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| SRCS = \ | |
| pow.c | |
| OBJS = $(subst .c,.o,$(SRCS)) | |
| CFLAGS = -fPIC | |
| LIBS = -shared -lm -ldl | |
| TARGET = libpow.so | |
| .SUFFIXES: .c .o | |
| all : $(TARGET) | |
| $(TARGET) : $(OBJS) | |
| gcc -o $@ $(OBJS) $(LIBS) | |
| .c.o : | |
| gcc -c $(CFLAGS) -I. $< -o $@ | |
| clean : | |
| rm -f *.o $(TARGET) |
This file contains hidden or 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
| #define _GNU_SOURCE | |
| #include <dlfcn.h> | |
| #include <stdlib.h> | |
| #include <math.h> | |
| static double (*___pow)(double, double); | |
| __attribute__((constructor)) | |
| double | |
| wrap_pow() { | |
| ___pow = dlsym(RTLD_NEXT, "pow"); | |
| } | |
| double | |
| pow(double x, double y) { | |
| system("aplay pow.wav 2> /dev/null"); | |
| return ___pow(x, y); | |
| } |
This file contains hidden or 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
| #include <stdio.h> | |
| #include <math.h> | |
| int | |
| main(int argc, char* argv[]) { | |
| printf("pow(4, 2) = %f\n", pow(4, 2)); | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment