Guest User

Untitled

a guest
Jan 17th, 2018
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.56 KB | None | 0 0
  1. /* libadd.c */
  2. #include <stdio.h>
  3.  
  4. extern int var;
  5.  
  6. int add(int a, int b) {
  7. return (a + b + var);
  8. }
  9.  
  10. gcc -c -Wall -Werror -fpic libadd.c
  11. gcc -shared -o libadd.so libadd.o
  12.  
  13. /* test.c */
  14. #include <stdio.h>
  15. #include "libadd.h"
  16.  
  17. int var = 1;
  18.  
  19. int main(void) {
  20. printf("%d", add(1,2));
  21. return 0;
  22. }
  23.  
  24. gcc -L/path/to/libadd -Wall -o test test.c -ladd
  25.  
  26. # test.py
  27. from ctypes import *
  28.  
  29. #what to do to define var?
  30.  
  31. sharedlib = CDLL("sharedlib/libadd.so", mode = RTLD_GLOBAL)
  32. print( sharedlib.add(1,2) )
  33.  
  34. OSError: sharedlib/libadd.so: undefined symbol: var
Add Comment
Please, Sign In to add comment