Skip to main content
Associate II
October 16, 2024
Question

Exclude from compiling one or more source file "for ever"

  • October 16, 2024
  • 5 replies
  • 1681 views

Hi all, I've a question.

I created a new project and there I linked externally some user made modules with the command Import (Right click kn project name, then choose import, add the wanted modules and linked them into the project).

I try to compile and everything was ok.

Now my question: I need to exclude some files from compiling process, both in debug and release mode. I was able to exclude them by the command "Resource Configuration" but when I delete and import again the modules, and link them again to the project, I see that the compiling filters has been restored to default values meanwhile I need to keep the filters on everytime.

 

There is a way to achieve this?

5 replies

Ghofrane GSOURI
ST Technical Moderator
October 16, 2024

Hello @zioMorgan 

First let me thank you for posting.

Try to follow  these steps  , you can manage file exclusions more effectively in STM32CubeIDE:

  • Create a Custom Build Configuration:
    • Set up a specific build configuration that excludes certain files. This way, you can switch between configurations without having to re-exclude files each time.
    • Check this post 
  • Use Project Properties:
    • Go to Project Properties > C/C++ General > Paths and Symbols > Source Location.
    • Here, you can manage file filters more effectively and ensure that your excluded files are noted for future reference
To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.
Associate
June 10, 2026

Hi,

I tried your method but it does not work.

CubeIDE Version 2.1.1

CubeMX Version 6.17.0

As far as I can tell the custom Build configurations are stored in the .cproject file.

I added two custom build configurations: NO_CDC and CDC2:

And then added a Filter under C/C++ General → Paths and Symbols → Source Location for both Custom configurations.

Those Filters show up in the .cproject file in lines 457 and 614:

<sourceEntries>
<entry excluding="Middlewares/ST/STM32_USB_Device_Library/" flags="VALUE_WORKSPACE_PATH" kind="sourcePath" name=""/>
</sourceEntries>

I attached two .cproject files in ZIP archive:

  1. Copy_of_.cproject: This file I saved after adding custom configurations and Filters in CubeIDE but before “GENERATE CODE” in CubeMX. You can see the Name of the Custom config in line 307 (and 476 resp.) . And you can see the excluded folder in line 457 (and 614 resp.)
  2. The .cproject file after “GENERATE CODE” in CubeMX. The two custom configs are still there but the exclusions in lines 457 and 614 are missing. Everything else is identical. I used Notepad++ with Compare plus plugin to compare the two files. There are only 6 lines different (2x 3 lines for the exclusions).

 

Can you confirm? And if so, report the bug please.

 

Thank you

 

Jan

Andrew Neil
Super User
June 10, 2026

It seems reasonable to me that deleting files from a Project would also remove any configurations for those files.

 

So why are you deleting them, only to import them again?

Perhaps explain what you’re actually trying to achieve here - there may be other ways to skin this cat…

 

Describe the goal, not the step

X-Y Problem

A complex system that works is invariably found to have evolved from a simple system that worked.A complex system designed from scratch never works and cannot be patched up to make it work.
Associate
June 10, 2026

Hi Andrew,

ahhh I see … I did not delete and import files like the thread opener. I just ran into the same question, which is “how to exclude certain files from compiling and making CubeIDE remember those exclusions even after code re-generation in CubeMX”. Then I follwed instruction given by Ghofrane GSOURI i.e. make a custom build config and set filter to make the exclusion permanent.

My question originates from the following situation: I use USB CDC on CM7 of a STM32H745 dual core MCU. CubeMX generates the STM32_USB_Device_Library under $projectRoot$/Middlewares/ST i.e. not in the Middlewares folder of CM7 but one level up.

But if I then compile the CM4 I get errors that e.g. usbd_cdc.h could not be found even though there is nothing relating to USB on the CM4, only CM7 (which by the way compiles just fine). I attached the IOC file.

Excluding the STM32_USB_Device_Library folder from compiling on the CM4 fixes the problem, i.e. the build compiles. But if I then “Generate Code” in CubeMX, even without making any changes, the exclusion is gone and the CM4 build fails with the above mentiones errors. Thats what I tried to say with my first post. 

 

Hope taht makes it clearer now.

 

Thanks,

 

Jan

Associate
June 10, 2026

Sorry for double post but I could not modify my previous post.

  1. I forgot to mention that the path to that STM32_USB_Device_Library is not specifically included on CM4. I don’t know why CubeIDE includes it in the first place. Maybe thats the real question here.
  2. The custom configs NO_CDC and CDC2 do the same because CDC2 was added for test purposes. I wanted to see if the exclusion is not deleted if the configuration (CDC2) is done by copying from a config that is not the debug config. I.e NO_CDC was derived by copying the current debug config and CDC2 was derived by copying from NO_CDC config. But in .cproject you can see that CDC2’s parent is also “debug” (line 476).