Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* libadd.c */
- #include <stdio.h>
- extern int var;
- int add(int a, int b) {
- return (a + b + var);
- }
- gcc -c -Wall -Werror -fpic libadd.c
- gcc -shared -o libadd.so libadd.o
- /* test.c */
- #include <stdio.h>
- #include "libadd.h"
- int var = 1;
- int main(void) {
- printf("%d", add(1,2));
- return 0;
- }
- gcc -L/path/to/libadd -Wall -o test test.c -ladd
- # test.py
- from ctypes import *
- #what to do to define var?
- sharedlib = CDLL("sharedlib/libadd.so", mode = RTLD_GLOBAL)
- print( sharedlib.add(1,2) )
- OSError: sharedlib/libadd.so: undefined symbol: var
Add Comment
Please, Sign In to add comment