harbor run -t LiteCoder/cmake-static-math-libraryharbor download LiteCoder/cmake-static-math-libraryCreate a C math utilities static library using CMake, build it, and link it into a separate test application. The entire project lives under /app.
/app/
├── mathlib/
│ ├── CMakeLists.txt
│ ├── include/
│ │ └── mathutils.h
│ └── src/
│ └── mathutils.c
├── app/
│ ├── CMakeLists.txt
│ └── main.c
└── CMakeLists.txt (top-level)
.a file)CMakeLists.txt must define the project name as MathProject and add both mathlib and app as subdirectoriesmathlib)The header file mathlib/include/mathutils.h must declare the following four functions:
double math_add(double a, double b) — returns a + bdouble math_subtract(double a, double b) — returns a - bdouble math_multiply(double a, double b) — returns a * bdouble math_divide(double a, double b, int *error) — returns a / b. If b is 0.0, set *error to 1 and return 0.0. Otherwise set *error to 0.The implementation goes in mathlib/src/mathutils.c.
The mathlib/CMakeLists.txt must:
mathutilsmathlib/include as a public include directory so consumers can use #include "mathutils.h"app)app/main.c must:
math_add(10.5, 3.2)math_subtract(10.5, 3.2)math_multiply(4.0, 2.5)math_divide(10.0, 3.0, &error)math_divide(10.0, 0.0, &error)add: 13.700000
subtract: 7.300000
multiply: 10.000000
divide: 3.333333
divide_by_zero_error: 1
printf with %f default formatting (6 decimal places) for numeric results. The divide-by-zero line prints the integer error flag.0.The app/CMakeLists.txt must:
math_appmathutils static library targetAfter all source files are in place, build the project from a build directory:
mkdir -p /app/build && cd /app/build && cmake .. && make
The built artifacts must include:
/app/build/mathlib/libmathutils.a/app/build/app/math_appRun the application:
/app/build/app/math_app
The output must exactly match the five lines specified above.