cancel
Showing results for 
Search instead for 
Did you mean: 

How can I make CubeIDE 1.16 generate and use precompiled headers?

ferro
Senior III

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

4 REPLIES 4
Pavel A.
Evangelist III

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

 

 

Thanks @Pavel A. - I posted my question after running example similar to yours.

I would like solution for CubeIDE.

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.

"the command to create precompiled headers in the pre-build step script"

That is axactly what I am after.