A magical C tool that transforms function definitions into header declarations automatically! β¨
Perfect for generating header files, creating APIs, and maintaining clean code structure!
Imagine you have a recipe book with detailed cooking instructions scattered everywhere. π
MDeclare is like a magic tool that:
- Reads your detailed recipes (C function definitions) π
- Creates a quick reference index (header declarations) ποΈ
- Gives you a clean table of contents (header file) β¨
If you have C code with functions like:
int add(int a, int b) { return a + b; }
void print_hello() { printf("Hello!"); }
double calculate_area(double radius) { return 3.14 * radius * radius; }
MDeclare transforms ALL of these into clean header declarations! π
- Before: Manually write declarations for every function π°
- After: One command creates all your headers automatically! π
- Before: Copy function signature, forget to add semicolon, mess up types...
- After: Perfect declarations every time! β¨
- Understand the difference between definitions and declarations
- See clean header structure instantly
- Learn proper C project organization
- Quickly generate headers for entire directories
- Keep your code organized and professional
- Easy API documentation generation
// calc.c - Basic arithmetic operations
int add(int a, int b) {
return a + b;
}
// subtract two integers
int subtract(int a, int b) {
return a - b;
}
// perform basic arithmetic operations
int multiply(int a, int b) {
return a * b;
}
int divide(int a, int b) {
if (b == 0) {
fprintf(stderr, "Error: Division by zero.\n");
return 0; // or handle error appropriately
}
return a / b;
}
mdeclare calc.c -o calc.h
// calc.c - Basic arithmetic operations
int add(int a, int b);
// subtract two integers
int subtract(int a, int b);
// perform basic arithmetic operations
int multiply(int a, int b);
int divide(int a, int b);
β¨ BOOM! Perfect header declarations with comments preserved!
π₯οΈ Platform | π¦ Download | π Description |
---|---|---|
π§ Linux | MDeclare.out | Ready-to-run executable |
πͺ Windows 32-bit | MDeclarei32.exe | Windows executable |
οΏ½ Ubuntu/Debian | MDeclare.deb | DEB package |
οΏ½ RHEL/Fedora | MDeclare.rpm | RPM package |
π File | π― Purpose |
---|---|
β‘ MDeclare.c | Single-file source code |
π MDeclareApiOne.c | API full for integration |
π§ MDeclareApiNoDependenciesIncluded.h | Amalgamator API |
Linux:
# Download and make executable
curl -L https://github.com/OUIsolutions/MDeclare/releases/download/0.2.0/MDeclare.out -o mdeclare && chmod +x mdeclare
Ubuntu/Debian:
# Install DEB package
wget https://github.com/OUIsolutions/MDeclare/releases/download/0.2.0/MDeclare.deb && sudo dpkg -i MDeclare.deb
Don't panic! This is easier than making instant noodles! π
Let's start with the simplest possible example:
# This is THE most basic command you'll ever need!
mdeclare my_functions.c -o my_functions.h
π€ What just happened?
my_functions.c
β "Hey MDeclare, read this C file!"-o my_functions.h
β "Put the header declarations in this file!"
That's it! MDeclare will:
- π Look at
my_functions.c
- π΅οΈββοΈ Find all function definitions
- π Extract the function signatures
- π Create clean header declarations in
my_functions.h
Imagine you have this C file:
math_utils.c:
#include <stdio.h>
// Calculate the square of a number
int square(int x) {
return x * x;
}
// Check if a number is even
bool is_even(int number) {
return (number % 2 == 0);
}
// Print a greeting message
void greet_user(const char* name) {
printf("Hello, %s! Welcome to our program!\n", name);
}
// Calculate factorial recursively
long factorial(int n) {
if (n <= 1) return 1;
return n * factorial(n - 1);
}
π Generate the header file:
mdeclare math_utils.c -o math_utils.h
π BOOM! You get this beautiful header:
math_utils.h:
// Calculate the square of a number
int square(int x);
// Check if a number is even
bool is_even(int number);
// Print a greeting message
void greet_user(const char* name);
// Calculate factorial recursively
long factorial(int n);
Now you can include this header in other files:
#include "math_utils.h"
int main() {
int result = square(5);
printf("Square of 5 is: %d\n", result);
return 0;
}
Got a whole directory of C files? No problem!
# Generate headers for ALL .c files in the src/ directory
mdeclare src/ -o project_headers.h --endswith ".c"
π€ What this does:
- Looks in the
src/
directory - Finds all files ending with
.c
- Extracts declarations from ALL of them
- Puts everything in one
project_headers.h
file
π Example project structure:
my_project/
βββ src/
β βββ calculator.c
β βββ file_utils.c
β βββ string_helpers.c
β βββ math_functions.c
βββ headers/
π One command generates everything:
mdeclare src/ -o headers/all_functions.h --endswith ".c" --include-path
β¨ The --include-path
flag adds helpful comments showing which file each function comes from!
π― Beginner Tip: Start with just the basic syntax:
mdeclare input.c -o output.h
. Learn the other options later!
π·οΈ Flag | π What It Does | π¨ Required? | π‘ Example |
---|---|---|---|
input_file |
The C file to read | β YES | mdeclare main.c |
-o , --output , --out |
Where to save the header | β YES | -o functions.h |
π·οΈ Flag | π What It Does | π‘ When to Use | π‘ Example |
---|---|---|---|
--startswith , --sw |
Only process files starting with this | Filter by filename prefix | --startswith "api_" |
--endswith , --ew |
Only process files ending with this | Filter by file extension | --endswith ".c" |
--include-path , --ip |
Add file path comments | Track which file each function comes from | --include-path |
π·οΈ Flag | π What It Does | π― Perfect For | π‘ Example |
---|---|---|---|
version , --version , -v |
Show MDeclare version | Checking what version you have | mdeclare version |
# Just convert one file - simple!
mdeclare calculator.c -o calculator.h
# Process all C files in a directory with path tracking
mdeclare src/ -o all_headers.h --endswith ".c" --include-path
# Process only API files starting with "api_"
mdeclare src/ -o api_headers.h --startswith "api_" --endswith ".c" --include-path
β DON'T DO THIS:
# Missing output flag - this will fail!
mdeclare main.c
β DO THIS INSTEAD:
# Always include the -o flag
mdeclare main.c -o main.h
β DON'T DO THIS:
# Using same name for input and output - BAD!
mdeclare functions.c -o functions.c
β DO THIS INSTEAD:
# Use different names to avoid overwriting
mdeclare functions.c -o functions.h
π― Beginner Note: This section is for people who want to use MDeclare inside their own C programs. If you just want to use the command-line tool, you can skip this section!
Download the API header file:
# Get the complete API (easiest way)
curl -L https://github.com/OUIsolutions/MDeclare/releases/download/0.2.0/MDeclareApiOne.h -o MDeclareApiOne.c
Create a file called my_header_generator.c
:
#include <stdio.h>
#include <stdlib.h>
#include "MDeclareApiOne.h"
int main() {
// Example C code with function definitions
const char *c_code =
"// Math utilities\n"
"int add(int a, int b) {\n"
" return a + b;\n"
"}\n"
"\n"
"// String utilities\n"
"void print_hello() {\n"
" printf(\"Hello, World!\\n\");\n"
"}\n";
// Transform it to header declarations! β¨
char *header_result = mdeclare_transform_content(c_code);
if (header_result == NULL) {
printf("β Oops! Something went wrong!\n");
return 1;
}
// Success! Print the header declarations
printf("β
Success! Here are your header declarations:\n\n%s", header_result);
// Clean up memory (important!)
free(header_result);
printf("\nπ All done!\n");
return 0;
}
Compile and run:
gcc my_header_generator.c -o my_header_generator
./my_header_generator
Expected output:
β
Success! Here are your header declarations:
// Math utilities
int add(int a, int b);
// String utilities
void print_hello();
π All done!
Want to process a whole directory? Here's how:
#include <stdio.h>
#include <stdlib.h>
#include "MDeclareApiOne.h"
int main() {
// Directory settings
const char *source_dir = "src/"; // Where your C files are
bool include_path = true; // Add file path comments
const char *starts_with = NULL; // Filter: files starting with...
const char *ends_with = ".c"; // Filter: files ending with...
// Process the entire directory! β¨
char *result = mdeclare_transform_dir(source_dir, include_path, starts_with, ends_with);
if (result == NULL) {
printf("β Oops! Something went wrong processing the directory!\n");
return 1;
}
// Write the result to a file
FILE *output_file = fopen("headers.h", "w");
if (output_file == NULL) {
printf("β Failed to create output file!\n");
free(result);
return 1;
}
fprintf(output_file, "%s", result);
fclose(output_file);
// Success! Print the combined headers
printf("β
Success! Processed directory '%s'\n", source_dir);
printf("π Generated headers saved to 'headers.h'\n");
printf("Preview:\n\n%s", result);
// Clean up memory (important!)
free(result);
printf("\nπ Directory processing complete!\n");
return 0;
}
π§ Function | π What It Does | π‘ Example |
---|---|---|
mdeclare_transform_content(content) |
Transform C code to header declarations | For single files or code strings |
mdeclare_transform_dir(dir_path, include_path, starts_with, ends_with) |
Process entire directories | For batch processing multiple files |
- Always check for NULL! The API functions can return NULL if something goes wrong.
- Don't forget to free memory! Always call
free()
on the returned strings when done. - Start simple! Use
mdeclare_transform_content()
first, then try the directory function.
π― Beginner Note: You don't need this section if you just downloaded the ready-made executables above! This is only for people who want to compile MDeclare themselves.
You'll need these tools installed:
- π¦ Darwin Build System (Version 0.8.0+)
- π³ Docker OR π« Podman (for containerized builds)
- π§ Linux Environment (recommended)
# Install Darwin build system in one command
curl -L https://github.com/OUIsolutions/Darwin/releases/download/0.8.0/darwin.out -o darwin.out && sudo chmod +x darwin.out && sudo mv darwin.out /usr/bin/darwin
# 1. Clone the repository
git clone https://github.com/OUIsolutions/MDeclare.git
cd MDeclare
# 2. Build all variants (this will take a while!)
darwin run_blueprint build/ --mode folder amalgamation_build alpine_static_build windowsi32_build windowsi64_build rpm_static_build debian_static_build --provider podman
π After building, you'll have:
- Linux executables
- Windows executables (32-bit and 64-bit)
- RPM packages
- DEB packages
- Static builds
- And more!
ποΈ Build Target | π Description | π― Output |
---|---|---|
amalgamation_build |
Single C file version | MDeclare.c |
alpine_static_build |
Static Linux binary | Linux executable |
windowsi32_build |
32-bit Windows | .exe file |
windowsi64_build |
64-bit Windows | .exe file |
rpm_static_build |
RPM package | .rpm file |
debian_static_build |
Debian package | .deb file |
β "darwin: command not found"
- Solution: Make sure Darwin is installed and in your PATH
β "Docker/Podman not found"
- Solution: Install Docker or Podman for containerized builds
β "Permission denied"
- Solution: Make sure you have execute permissions on build scripts
- π Found a Bug? Create an Issue
- π‘ Have a Feature Idea? Suggest It Here
- β Like the Project? Give us a star on GitHub!
Q: "Can I use this with C++?" A: MDeclare is designed for C, but it might work with simple C++ code. Try it and see!
Q: "What about very complex function definitions?" A: MDeclare handles most standard C functions. For very complex cases, you might need to manually adjust the output.
Q: "Can I process only specific files in a directory?"
A: Yes! Use --startswith
and --endswith
flags to filter which files get processed.
Q: "Is it safe to use in production?" A: Absolutely! Many developers use MDeclare for generating headers. Just test thoroughly first.
- π Students: Generate clean headers for assignments and projects
- π Professional Development: Maintain consistent API documentation
- π¦ Library Creation: Quickly generate header files for C libraries
- π Large Projects: Automatically maintain headers across multiple files
- π± Embedded Systems: Clean interface definitions for hardware projects
"MDeclare saved me hours of manually creating header files!" - DevStudent2024
"Perfect for keeping my C projects organized and professional!" - CodeMaster
"Made generating API documentation so much easier!" - LibraryDev
Made with β€οΈ by OUIsolutions
Transforming C definitions into perfect headers, one function at a time! β¨