Last active
April 26, 2016 12:36
-
-
Save ctison/e42562f82a03cd6dc44629599a12cd18 to your computer and use it in GitHub Desktop.
Call C code from Python
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
#include <stdio.h> | |
void ft_say_hello(void) { | |
printf("Hello World !\n"); | |
return ; | |
} |
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
from ctypes import cdll | |
libft = cdll.LoadLibrary('./libft.so') | |
libft.ft_say_hello() |
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: | |
# Creer le fichier 'ft_say_hello.o' | |
gcc -c ft_say_hello.c | |
# Mettre le fichier 'ft_say_hello.o' dans une bibliotheque | |
# dynamique 'libft.so' | |
gcc -shared -o libft.so ft_say_hello.o | |
# Executer le fichier python 'main.py' qui va chercher le symbole | |
# ft_say_hello dans la librairie dynamique et l'executer | |
python main.py | |
clean: | |
@rm -f -- ft_say_hello.o libft.so | |
fclean: clean | |
re: fclean all |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment