See IncludeBuild in action with these practical examples
A minimal example that demonstrates the simplest use of IncludeBuild. Just include build.h, call ib_init() and ib_build() - that's it!
/**
* IncludeBuild Basic Example
*/
#include "../../build.h"
#include <stdio.h>
int main() {
// Initialize IncludeBuild
ib_init();
// Enable verbose output
ib_set_verbose(true);
// Build the project
ib_build();
printf("\nBuild complete!\n");
return 0;
}
Demonstrates how IncludeBuild automatically handles a project with multiple source files and resolves dependencies between them.
/**
* IncludeBuild Multi-File Example
*/
#include "../../build.h"
#include <stdio.h>
int main() {
// Initialize IncludeBuild
ib_init();
// Enable verbose output
ib_set_verbose(true);
// Build the project - build.h finds all source files automatically
ib_build();
printf("\nBuild complete!\n");
return 0;
}
Shows how to create a complete library with static and dynamic versions plus tests with just TWO LINES of code.
/**
* IncludeBuild Library Example - The Magic Solution
*/
#include "../../build.h"
int main(int argc, char** argv) {
// Initialize IncludeBuild
ib_init();
// Enable verbose output
ib_set_verbose(true);
// Build the library - this handles everything: static, dynamic, tests
return ib_build_library("logger", argc, argv) ? 0 : 1;
}
A complete Pong game using the Raylib external library, demonstrating IncludeBuild's ability to handle dependencies and cross-platform builds.
/**
* IncludeBuild Game Example
*/
#include "../../build.h"
#include <stdio.h>
int main() {
// Initialize IncludeBuild
ib_init();
// Enable verbose output
ib_set_verbose(true);
// Add Raylib and its dependencies
ib_add_libraries("raylib", "GL", "m", "pthread", "dl", "rt", "X11", NULL);
// Build the project
ib_build();
printf("\nBuild complete!\n");
return 0;
}
Demonstrates IncludeBuild's logging features with different verbosity levels, allowing for detailed build information and debugging.
/**
* IncludeBuild Logging Example
*/
#include "../../build.h"
#include <stdio.h>
#include <string.h>
int main(int argc, char** argv) {
// Initialize IncludeBuild
ib_init();
// Enable verbose output
ib_set_verbose(true);
// Set a different log level if specified
if (argc > 1) {
if (strcmp(argv[1], "debug") == 0)
ib_set_log_level(IB_LOG_DEBUG); // Most verbose
else if (strcmp(argv[1], "warn") == 0)
ib_set_log_level(IB_LOG_WARN); // Warnings and errors
else if (strcmp(argv[1], "error") == 0)
ib_set_log_level(IB_LOG_ERROR); // Errors only
}
// Build the project
ib_build();
return 0;
}
Demonstrates how to customize IncludeBuild's internal limits for larger projects by defining constants before including build.h.
/**
* IncludeBuild Custom Limits Example
*/
// Define custom limits before including build
#define IB_MAX_FILES 2000 // Default is 1000
#define IB_MAX_DEPS 200 // Default is 100
#define IB_MAX_INCLUDE_DIRS 100 // Default is 50
#include "../../build.h"
#include <stdio.h>
int main() {
// Initialize IncludeBuild
ib_init();
ib_set_verbose(true);
// Print custom limits
printf("\nCustom limits in effect:\n");
printf(" IB_MAX_FILES: %d\n", IB_MAX_FILES);
printf(" IB_MAX_DEPS: %d\n", IB_MAX_DEPS);
// Build the project
ib_build();
return 0;
}
These examples are just the beginning. IncludeBuild is flexible enough to handle many different use cases. We encourage you to experiment with these examples and create your own!
If you develop an interesting example, consider contributing it back to the project.