2023-01-05 21:13:10 +01:00
< h1 align = "center" > libcproject< / h1 >
< p align = "center" >
< strong > C static library easier to use than `libc` (C standard library).</ strong >
< / p >
< p align = "center" >
2023-12-26 19:42:12 +01:00
< a href = "./CONTRIBUTING.md" > < img src = "https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat" alt = "Contributing" / > < / a >
2023-01-05 21:13:10 +01:00
< a href = "./LICENSE" > < img src = "https://img.shields.io/badge/licence-MIT-blue.svg" alt = "Licence MIT" / > < / a >
< a href = "./CODE_OF_CONDUCT.md" > < img src = "https://img.shields.io/badge/Contributor%20Covenant-v2.0%20adopted-ff69b4.svg" alt = "Contributor Covenant" / > < / a >
< br / >
2023-12-26 19:42:12 +01:00
< a href = "https://github.com/theoludwig/libcproject/actions/workflows/ci.yml" > < img src = "https://github.com/theoludwig/libcproject/actions/workflows/ci.yml/badge.svg?branch=develop" alt = "CI" / > < / a >
2023-01-05 21:13:10 +01:00
< a href = "https://conventionalcommits.org" > < img src = "https://img.shields.io/badge/Conventional%20Commits-1.0.0-yellow.svg" alt = "Conventional Commits" / > < / a >
< a href = "https://github.com/semantic-release/semantic-release" > < img src = "https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg" alt = "semantic-release" / > < / a >
< / p >
2023-01-05 19:28:05 +01:00
## About
2023-01-05 21:13:10 +01:00
**libcproject** is a C static library for learning purposes. It tries to implement useful functions/data structures while being easier to use than `libc` (C standard library) as much as possible.
C is a low-level programming language and we often end up reinventing the wheel as the C standard library (`libc`) is quite small and in my humble opinion, not well designed.
2023-08-06 16:12:10 +02:00
**libcproject** solve this by providing common functions or data structures (`hash_map`, `array_list` , `linked_list` , `queue` , `stack` , etc.), we might need in our C projects.
2023-01-05 19:28:05 +01:00
2023-01-06 17:46:23 +01:00
[Online documentation ](https://libcproject.vercel.app/ ).
2023-01-05 19:28:05 +01:00
## Prerequisites
- [GNU coreutils ](https://www.gnu.org/software/coreutils/ )
- [GNU binutils ](https://www.gnu.org/software/binutils/ )
- [GNU gcc ](https://gcc.gnu.org/ )
- [GNU make ](https://www.gnu.org/software/make/ )
2023-01-06 18:08:34 +01:00
- [ClangFormat ](https://clang.llvm.org/docs/ClangFormat.html )
2023-01-06 16:32:29 +01:00
- [Doxygen ](https://www.doxygen.nl/ )
2023-01-05 19:28:05 +01:00
For example on GNU/Linux Ubuntu:
```sh
2023-08-06 16:12:10 +02:00
# Install Build Tools
2023-08-09 20:29:19 +02:00
sudo apt install build-essential gcc make clang-format
2023-08-06 16:12:10 +02:00
# Install Documentation Tools
2023-08-09 20:29:19 +02:00
sudo apt install doxygen doxygen-gui doxygen-doc graphviz
2023-01-05 19:28:05 +01:00
```
## Usage
2023-01-05 21:13:10 +01:00
```sh
make # to compile
make run # to run main
make test # to run unit tests
make lint # to lint the code
2023-01-06 16:32:29 +01:00
make documentation # to generate the documentation
2023-01-05 21:13:10 +01:00
make clean # to clean up
nm ./build/libcproject.a # to see the symbols
```
2023-01-05 19:28:05 +01:00
Steps to create a new C project that uses `libcproject` :
2023-08-06 16:12:10 +02:00
### Step 1: Create a new project
```sh
mkdir my-project
cd my-project
```
### Step 2: Install and Compile `libcproject` in the project
2023-01-05 19:28:05 +01:00
```sh
2023-01-07 18:57:14 +01:00
# Clone the repository
2023-06-24 20:29:30 +02:00
git clone git@github.com:theoludwig/libcproject.git
2023-01-07 18:57:14 +01:00
# Go to libcproject directory
cd libcproject
# Compile the library
2023-01-05 19:28:05 +01:00
make
```
2023-08-06 16:12:10 +02:00
### Step 3: Create a new C file
2023-01-05 19:28:05 +01:00
```sh
2023-08-06 16:12:10 +02:00
cd ..
2023-01-05 19:28:05 +01:00
touch main.c
```
```cpp
#include <stdio.h>
#include <stdlib.h>
#include "libcproject/libcproject.h"
int main() {
2023-08-06 23:17:07 +02:00
string_t string = "Hello, world!"; // `string_t` is a typedef from `libcproject`
printf("%s\n", string);
printf("string_length = %ld\n", string_get_length(string)); // `string_get_length` is a function from `libcproject`
2023-01-05 19:28:05 +01:00
return EXIT_SUCCESS;
}
```
2023-08-06 16:12:10 +02:00
### Step 4: Compile your project and link it with the library
2023-01-05 19:28:05 +01:00
```sh
2023-06-25 20:17:28 +02:00
gcc -o ./main ./main.c -L. -l:./libcproject/build/libcproject.a
2023-01-05 19:28:05 +01:00
```
2023-01-05 21:13:10 +01:00
## 💡 Contributing
2023-01-05 19:28:05 +01:00
2023-01-05 21:13:10 +01:00
Anyone can help to improve the project, submit a Feature Request, a bug report or even correct a simple spelling mistake.
2023-01-05 19:28:05 +01:00
2023-01-05 21:13:10 +01:00
The steps to contribute can be found in the [CONTRIBUTING.md ](./CONTRIBUTING.md ) file.
## 📄 License
[MIT ](./LICENSE )