This project was created using functions in the C programming language that I developed during the selection process, known as the Piscine, at Hive Helsinki. Hive is part of the 42 School Network, which emphasizes peer-to-peer learning and the development of skills in creative problem-solving, teamwork, autonomy, responsibility, logic, and rigor. After completing the Piscine, I was selected for the core educational program.
This static library includes two standard C libraries: <unistd.h>
, which provides the write()
function, and <stdlib.h>
, which is used for memory management with malloc()
and free()
. By including the header file #include "libpiscine.h"
in your project, you will also have access to its functions.
A list of all the functions included in the Piscine library can be found in the include/libpiscine.h header file. Each function is also accompanied by a short annotation inside its source file.
hive-piscine-c-library/
│
├── include/
│ └── libpiscine.h
│
├── src/
│ ├── ft_atoi.c
│ ├── ft_is_prime.c
│ ├── ft_putnbr.c
│ ├── ...
│ └── ft_ultimate_range.c
│
├── test/
│ ├── test_main.c # Test source file
│ └── test_main # Test program created after compilation
│
├── lib/ # Directory created after compilation
│ └── libpiscine.a # Static library file created after compilation
│
├── obj/ # Directory created after compilation
│ ├── ft_atoi.o # Object file created after compilation
│ ├── ft_is_prime.o
│ ├── ft_putnbr.o
│ ├── ...
│ └── ft_ultimate_range.o
│
└── Makefile # Script to automate compilation process
To use this library in your project, follow these steps:
- Clone the Repository.
git clone https://github.com/ucylama/hive-piscine-c-library.git repository-name
cd repository-name
- Build the Library.
Use the Makefile to compile the source files and create the static library.
This will generate:- object files (
ft_*.o
) in the./obj
directory. - a static library file (
libpiscine.a
) in the./lib
directory.
- object files (
make
- Include the Header File in your source code.
#include "libpiscine.h"
- Include the Library in the Project.
Link the static library in your project's build process to use the functions as described in the header file. For example, if usinggcc
, you can compile and link your project with the library as follows:
gcc -Iinclude -o program_name program_name.c -Llib -lpiscine
Flags and arguments:
-Iinclude
tells the compiler to look in theinclude
directory for any header files that are included in the source code.-o program_name
specifies the name of the output file.program_name.c
is the name of the source file to be compiled.-Llib
tells the linker to look in the lib directory for any libraries that are specified with the-l
option.-lpiscine
means that the linker should link the program with thelibpiscine.a
library (the lib prefix and the.a
extension are added automatically by the linker).
Recommended additional flags:
-Wall -Wextra -Werror
to enable warning messages and to tell the compiler.-std=c99
to use the C99 standard for the C programming language.
To test the library and ensure that everything is working correctly, follow these steps:
- Build the Test Executable.
Compile the test file test_main.c with the library:
make test
- Run the Tests.
Execute the test binary to run the tests:
./test/test_main
To clean up the object files, test executable, and library files, run:
make clean
To remove all build artifacts and directories:
make re
The Makefile
contains settings that are specific to different operating systems. Here’s a brief explanation of these settings:
ifeq ($(OS),Windows_NT) # Checks if the operating system is Windows.
RM = del /q # Defines the command to remove files.
RM_DIR = rmdir /s /q # Defines the command to remove directories.
LIB_EXT = .lib # Sets the library file extension for Windows.
else # Applies to Unix-like systems.
RM = rm -f # Defines the command to remove files.
RM_DIR = rm -rf # Defines the command to remove directories.
LIB_EXT = .a # Sets the library file extension.
endif
Developed by Julia Persidskaia.
LinkedIn