examplelib
Contoh library C yang reusable untuk pembelajaran cara membangun, menguji, dan mendistribusikan library C.
Struktur Proyek #
text
examplelib/
├── include/
│ └── examplelib.h # Public API
├── src/
│ └── examplelib.c # Implementasi
├── tests/
│ └── test_examplelib.c # Unit test
├── Makefile # Build manual (gcc + ar)
├── CMakeLists.txt # Build dengan CMake
└── README.mdBuild dengan Make #
bash
make # Bangun static + shared + test
make static # Hanya libexamplelib.a
make shared # Hanya libexamplelib.so
make test # Build dan jalankan test
make install # Install ke /usr/local (perlu sudo)Build dengan CMake #
bash
cmake -S . -B build -DCMAKE_BUILD_TYPE=Release
cmake --build build
ctest --test-dir build
sudo cmake --install build # opsionalUntuk membangun shared library lewat CMake:
bash
cmake -S . -B build-shared -DBUILD_SHARED_LIBS=ON
cmake --build build-sharedAPI Singkat #
| Fungsi | Tugas |
|---|---|
exlib_version() | Versi library sebagai string |
exlib_mean() | Hitung rata-rata array double |
exlib_stddev() | Hitung standar deviasi populasi |
exlib_reverse_bytes() | Balik urutan byte in-place |
exlib_format_size() | Format ukuran byte ke “1.50 KB” dst. |
exlib_contains() | Cek substring ada di string |
exlib_strerror() | Pesan singkat untuk kode error |
Kode Error #
| Kode | Nilai | Arti |
|---|---|---|
EXLIB_OK | 0 | sukses |
EXLIB_ERR_NULL | -1 | pointer NULL atau n=0 |
EXLIB_ERR_RANGE | -2 | nilai di luar rentang valid |
EXLIB_ERR_FORMAT | -3 | format input tidak valid |
EXLIB_ERR_OVERFLOW | -4 | potensi overflow |
EXLIB_ERR_NOT_FOUND | -5 | tidak ditemukan |