Skip to content

Instantly share code, notes, and snippets.

@ctison
Last active April 26, 2016 12:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ctison/e42562f82a03cd6dc44629599a12cd18 to your computer and use it in GitHub Desktop.
Save ctison/e42562f82a03cd6dc44629599a12cd18 to your computer and use it in GitHub Desktop.
Call C code from Python
#include <stdio.h>
void ft_say_hello(void) {
printf("Hello World !\n");
return ;
}
from ctypes import cdll
libft = cdll.LoadLibrary('./libft.so')
libft.ft_say_hello()
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