본문 바로가기

개발 이야기/파이썬 개발

파이썬에서 C함수 사용하기

728x90

CPython이 개발자에게 제공하는 흥미로운 기능은 C 코드와 Python의 인터페이스 용이성 입니다.

개발자가 Python 코드에서 C 함수를 호출하는 데 사용하는 세 가지 주요 방법은 ctypes, SWIG 및 Python / C API가 있습니다. 

 

1. ctypes 예:  https://ddanggle.gitbooks.io/interpy-kr/content/c.html

 

파이썬 C 확장 · interpy-kr

 

ddanggle.gitbooks.io

2. SWIG: https://forcecore.tistory.com/1270

 

SWIG와 Python3... C++ 클래스를 Python 3에서 사용하기

일단 swig를 설치한다. Python에서도 쓰고싶은 C++ 클래스를 준비한다. 이미 만들어져 있다고 치자. 필자의 경우는 mo_solver.h 란 직접 만든 헤더파일이다. 이 안엔 클래스가 여러개 들어있다. 우선은

forcecore.tistory.com

 

3. Python C/C++ API: https://booolean.tistory.com/895

 

Python - C/C++ API Reference Manual Introduction

Embedding & Extended Python / C&CPP Introduction Python 인터페이스를 통해 C 및 C ++ 프로그래머는 Python 인터프리터에 액세스 할 수 있다. API는 C ++에서도 똑같이 사용할 수 있다. 특정 목적을 위해 확장..

booolean.tistory.com

 

728x90