Examples
See IncludeBuild in action with these practical examples.
Basic
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
*/
#define INCLUDEBUILD_IMPLEMENTATION
#include "../../build.h"
#include <stdio.h>
int main() {
// Initialize IncludeBuild
ib_init();
// Enable verbose output
ib_set_verbose(true);
// Build the project - explicitly name it "main"
ib_add_target("main", "main.c");
ib_build();
printf("\nBuild complete! Run './main' to execute the program.\n");
return 0;
}
Multi-file
Demonstrates how IncludeBuild automatically handles a project with multiple source files and resolves dependencies between them.
/**
* IncludeBuild Multi-File Example
*/
#define INCLUDEBUILD_IMPLEMENTATION
#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! Run './main' to execute the program.\n");
return 0;
}
Game
A complete Pong game using the Raylib external library. IncludeBuild includes Raylib binaries for Windows (MinGW) out-of-the-box, so you can build it immediately. On Linux, system libraries are used.
/**
* IncludeBuild Game Example
*/
#define INCLUDEBUILD_IMPLEMENTATION
#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_include_dir("vendor/raylib/include");
ib_add_library_path("vendor/raylib/lib");
#ifdef _WIN32
ib_add_libraries("raylib", "opengl32", "gdi32", "winmm", NULL);
#else
ib_add_libraries("raylib", "GL", "m", "pthread", "dl", "rt", "X11", NULL);
#endif
// Build the project - explicitly name it "main"
ib_add_target("main", "main.c");
ib_build();
printf("\nBuild complete! Run './main' to play the game.\n");
return 0;
}
Logging
Demonstrates IncludeBuild's logging features with different verbosity levels, allowing for detailed build information and debugging.
/**
* IncludeBuild Logging Example
*/
#define INCLUDEBUILD_IMPLEMENTATION
#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
for (int i = 1; i < argc; ++i) {
if (strcmp(argv[i], "debug") == 0)
ib_set_log_level(IB_LOG_DEBUG); // Most verbose
else if (strcmp(argv[i], "warn") == 0)
ib_set_log_level(IB_LOG_WARN); // Warnings and errors
else if (strcmp(argv[i], "error") == 0)
ib_set_log_level(IB_LOG_ERROR); // Errors only
else if (strcmp(argv[i], "verbose") == 0)
ib_set_verbose(true); // Toggle verbose mode
}
// Build the project - explicitly name it "main"
ib_add_target("main", "main.c");
ib_build();
printf("\nBuild complete! Run './main' to execute the program.\n");
return 0;
}
Custom Limits
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
#define INCLUDEBUILD_IMPLEMENTATION
#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 (default: 1000)\n", IB_MAX_FILES);
printf(" IB_MAX_DEPS: %d (default: 100)\n", IB_MAX_DEPS);
printf(" IB_MAX_INCLUDE_DIRS: %d (default: 50)\n", IB_MAX_INCLUDE_DIRS);
// Build the project - explicitly name it "main"
ib_add_target("main", "main.c");
ib_build();
printf("\nBuild complete! Run './main' to execute the program.\n");
return 0;
}