2024-11-28 12:19 PM
Hi,
Aiming to speed up build times, I would like to explore precompiled headers.
How can I make CubeIDE 1.16 generate and use precompiled headers?
Thank you
Ferro
2024-11-28 12:46 PM - edited 2024-11-28 01:18 PM
GCC compiler shipped with CubeIDE should support precompiled headers. Please see GCC documentation for command line syntax.
Below is a small example for gcc created by AI (imagine that!)
----- this is common .h file to precompile: -----
#ifndef COMMON_H
#define COMMON_H
#include <stdio.h>
void greet(const char* name);
#endif
------ First C file using the common .h -----
// common.c
#include "common.h"
void greet(const char* name) {
printf("Hello, %s!\n", name);
}
------ Another C file using the common .h -----
// main.c
#include "common.h"
int main() {
greet("GCC User");
return 0;
}
-------- Commands to build --------
# Create the precompiled header for common.h, it will be common.h.gch
gcc -x c-header common.h
# For C++ use command:
# g++ -x c++-header common.h
# Build the program
gcc main.c common.c -o prog
2024-11-28 01:34 PM
Thanks @Pavel A. - I posted my question after running example similar to yours.
I would like solution for CubeIDE.
2024-11-28 02:01 PM
In CubeIDE you can put the command to create precompiled headers in the pre-build step script. As the example shows, no other compiler options are needed. The gch files should be used automatically if they exist.
2024-11-28 02:09 PM
"the command to create precompiled headers in the pre-build step script"
That is axactly what I am after.