Last active
November 25, 2016 04:04
-
-
Save kmwenja/8f6602b2552460892a029d6a342f2db4 to your computer and use it in GitHub Desktop.
Use linux dynamic libraries in python. First run `make` then `python main.py`
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
Using linux dlls in python. | |
1. `make` | |
2. `python main.py` |
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
int add(int a, int b){ | |
return a + b; | |
} |
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
import os | |
from ctypes import cdll | |
THIS_DIR = os.path.join( | |
os.path.dirname(os.path.abspath(__file__))) | |
libadd = cdll.LoadLibrary(os.path.join(THIS_DIR, "libadd.so")) | |
print(libadd.add(1, 3)) |
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: libadd.so | |
libadd.so: add.o | |
# make shared dll | |
gcc -shared -o libadd.so add.o | |
add.o: | |
# ensure you compile with position independent code (PIC) | |
gcc -c -fPIC -o add.o add.c | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment