C Usage with CMake and Meson
Prerequisites
Before proceeding, ensure the following are installed and set up:
- C Compiler: Ensure you have a C compiler installed. For example,
gccon Linux. - filerix: Ensure the
filerixlibrary and its development files are installed.
CMake Prerequisites
- CMake: Install CMake. If you don't have it already:
Meson Prerequisites
- Meson: Install Meson. If you don't have it already:
Installing Dependencies
Depending on your distribution, run one of the following commands to install the required build tools:
sudo dnf install cmake make meson ninjasudo apt install cmake make meson ninjasudo pacman -Syu cmake make meson ninjaBuilding the Example with CMake
Navigate to the
example/c+cmakedirectory:bashcd example/c+cmakeCreate a build directory to keep the build files organized:
bashmkdir build cd buildRun
cmaketo configure the project:bashcmake ..Build the project with
make:bashmakeAfter building, the executable
examplewill be available in thebuilddirectory.
Building the Example with Meson
Navigate to the
example/c+mesondirectory:bashcd example/c+mesonCreate a build directory to keep the build files organized:
bashmkdir build cd buildRun
mesonto configure the project:bashmeson ..Build the project with
ninja:bashninjaAfter building, the executable
examplewill be available in thebuilddirectory.
Running the Example
Once the build process completes, run the compiled executable:
bash./exampleThe example will fetch and log the disk usage information for the specified path (
/by default). You should see output like this:bashUsed space: <used_bytes> bytes Total space: <total_bytes> bytes
Understanding the Code
The C code interacts with the filerix library to fetch the disk usage of a given directory (/ by default). Here’s a quick breakdown of the key components:
- GetDriveUsage: This function retrieves the disk usage details (used space and total space) for the given path.
- printf: The result is printed to the console for the user to see.
This simple program is designed to showcase how to use filerix for filesystem operations and how to integrate it into a C++ project with CMake and Meson.
Common Issues
Missing
filerix.so(Shared Library): If you encounter errors about missing libraries (e.g.,filerix.so), ensure the library path is correctly set:bashexport LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATHIf
filerixwas installed manually, ensure the path where it's located is included inLD_LIBRARY_PATH.
