This is my own wrapper to compile C with the GCC compiler.
The idea is to have a set of defaults (warnings, security, and standards) and a set of commands to simplify actions. You can compile at any time with different defaults, making it flexible and easy to adapt to various projects.
This project is inspired by nobuild.
-
Default Compilation Flags: Predefined set of compilation flags for better security and standards compliance.
-
Simplified Commands: Easy-to-use commands for common tasks like building, running, and creating object files.
- build: Compile all the files with the previously set defaults.
- run: Compile and run the files, then remove the executable.
- obj: Create only object files.
- Get the
jcc.c
file. - Create a
jcc_init.c
file (or any other name). Example:jcc_init.c
#include "./jcc.c"
int main(int argc, char* argv[argc]) {
//must be a null terminated array
char const*const defaults[] = {
"-std=c23",
"-O2",
"-Wall",
"-Wextra",
"-D_FORTIFY_SOURCE=2",
0
});
return jcc_init(defaults, argc, argv);
}
-
Compile the
jcc_init.c
file. The project uses some C11 features, so it must be compiled with-std=c11
. The last GCC compiler's default standard is C11 (I think), so you do not need to specify the-std=
option. -
Then you can create an alias or add it to your PATH in your system.
Voilà
You only need these function jcc_init()
and an null terminated array of
default commands.
You can pass the a null pointer insted of the array to use the gcc defaults.
You can change the command name that appears on the console prompts and errors by defining the JCC_NAME header.
Example 'c99.c':
#define JCC_NAME "c99"
#include "./jcc.c"
int main(int argc, char* argv[argc]) {
char const*const defaults[] = {
"-std=c99",
0
};
return jcc_init(defaults, argc, argv);
}
Now when you call c99 help [commands]
c99 appears as the name of the
command.
This project was created with some Linux headers and obviously depends on GCC. It has only been tested on my own computer.