Some Hints About Building Projects

The CodeBlocks IDE is designed to be easy to use: you set up the project Build Options, and then just hit Project->Build (Ctrl-F9), and it does the job for you. Here are a few additional hints that may not be obvious:

Building ST’s Library Files

If you are building ST’s library files (e.g. ST’s HAL or Standard Peripheral Library SPL files), you may receive an error message similar to this:

Please select first the target STM32F7xx device used in your application (in stm32f7xx.h file)

The exact message depends on which STM32 MCU you are using. The problem is simply that the ST header file is expecting a #define for a particular MCU to exist. If you click on the error message in the Build Message window, you should see something similar to the stm32f?xx.h file:

#if defined(STM32F756xx)

  #include "stm32f756xx.h"

#elif defined(STM32F746xx)

  #include "stm32f746xx.h"

#elif defined(STM32F745xx)

  #include "stm32f745xx.h"


 #error "Please select first the target STM32F7xx device used in your application (in stm32f7xx.h file)"


In this case, it is expecting one of STM32F756xx, STM32F746xx, STM32F745xx to be defined. Select the device family that is closest to your target device (if there is nothing that matches, then you may be need to download a later version of the ST library). For example, let’s say you are using a STM32F746ZG, then add the following to the Project->Build Options->Compiler/Linker tab, under the compiler section:


This will prevent the error from happening.

Autosaving Changed Files

Project files with unsaved changes (e.g. open in the editors) will be saved automatically before the build is performed.

NOTE: only files that are explicitly present in the project file list will be autosaved. For example, in the case of a header file that is included in the source file, you must also add the header file to the project file list for this autosave action to take effect on the header file.



Improving Build Time

To improve build time, you can use more than one processor to concurrently perform multiple compile operations. Invoke Settings->Compiler…->Build Options tab. Set “# of processes for parallel build” to at least 4 for a modern PC. It probably should not be higher than the number of threads or cores that your CPU can support. Doing this will improve the build time significantly.

Changing the Order of File Building

In the project file list, the source files are always displayed in alphabetical order. CodeBlocks automatically generates the build dependency, and the source file compilation order is determined by internal algorithm to take advantage of the multiple processes available to do the build.


In rare occasions, if you want to specify certain file(s) to be compiled before other file(s), you can do this by: first, set the “# of processes for parallel build” to 1 as above, and then files with same priority weight are built in the file order on the project file list.


To change the priority weight of a file, right-click on the file name in the project file list, then click Properties, and switch to the Build tab.


The Priority Weight slider, which ranges from 0 to 100, with 50 being the default weight, specifies the build order. Normally all files have the same weight (50). A file with a smaller priority weight number has a "higher priority"; it will be built before a file with a larger priority weight number.





“Cannot Create Process…” Build Error

In rare occasions, a Build might fail with an error message about “Cannot Create Process…” this is probably when the system is bumping up against some Windows resource limits (e.g. too many applications are running). Closing down unused apps or decreasing the number of processes for parallel build will likely fix the problem.