UL
Ulincsys/Mizzou_CS2050_FS232_Surprise
Library examples
This repo contains examples of compiling, linking, and loading C libraries in both C and Python.
Building in C
The provided makefile defines three targets for building, as a way to demonstrate each method of linking.
make main-static- Compile main.c and mylib.c and link statically
make main-shared- Compile main.c and mylib.c and link as shared library
make main-dynamic- Compile dyn_main.c and mylib.c, and do not link
Running in C
For the main-static and main-dynamic build targets, you can simply run the resulting executable with:
./a.outHowever, the main-shared target requires you to add the libs folder to the LD_LIBRARY_PATH, a la:
LD_LIBRARY_PATH=libs:$LD_LIBRARY_PATH ./a.outThe LD_LIBRARY_PATH variable tells the shared object loader where to find library files on startup. By default, programs will look in your system library folders (IE: /usr/lib on Linux) first, and then wherever you tell them to after.
Running in Python
Compile the shared library file first, and then launch main.py with Python:
make library
python3 main.py
On this page
Languages
C65.2%Python23.7%Makefile11.1%
Contributors
Created November 17, 2023
Updated November 17, 2023