How to use your clibrary in Python with ctypes.
To get started with this project locally, yourself you first need a few prerequisites. This project was built for macOS and may need a few tweaks to get started on Windows or Linux.
For this project you will need:
- Cmake
- C compiler
- Python3
This instructions show how to do this on macOS, for Linux or Windows please check the specific installations.
- Install homebrew
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
- Install cmake, gcc and Python3
brew update
brew install cmake gcc pyenv
pyenv install 3.9.1
- Download this repository and set a local Python version
git clone https://github.com/henriwoodcock/c-in-my-python.git
cd c-in-my-python
pyenv local 3.9.1
To build the library we create a build directory, use cmake to build the makefiles and finally build the application.
mkdir build
cd build
cmake ..
make -j8
cd ../
Before running in Python, make sure the c application has build correctly:
./run_tests.sh
The c library will now be used in Python:
python main.py
You should see "ALL TESTS PASSED".