Build and Clean Selected Files in Eclipse CDT

Sometimes it is very useful to clean or build a selected set of files. For this I select the file(s) in the Eclipse Project Explorer and use the context menu:

Build Selected Files

Build Selected Files

This is handy to quickly check if a source modification builds fine, without the need to rebuild a large set of files:

09:55:47 **** Building Selected Files of configuration Debug for project FRDM-K64F_Fusion ****
Info: Internal Builder is used for build
arm-none-eabi-gcc -mcpu=cortex-m4 -mthumb -mfloat-abi=hard -mfpu=fpv4-sp-d16 -O0 -fmessage-length=0 -fsigned-char -ffunction-sections -fdata-sections -Wall -g3 "-I..\\Generated_Code" -I../Sources -I../Project_Settings/Startup_Code "-IC:\\nxp\\KDS_3.2.0\\eclipse\\ProcessorExpert/lib/Kinetis/iofiles" "-IC:\\nxp\\KDS_3.2.0\\eclipse\\ProcessorExpert/lib/Kinetis/pdd/inc" "-IC:/Users/Erich Styger/Data/HSLU/Vorlesung/nemesis/CCE/Eck/KDS/FRDM_K64F_Fusion/Sources" "-IC:/Users/Erich Styger/Data/HSLU/Vorlesung/nemesis/CCE/Eck/KDS/FRDM_K64F_Fusion/Generated_Code" "-IC:\\nxp\\KDS_3.2.0\\eclipse\\ProcessorExpert/Repositories/Kinetis_Repository/lib/Kinetis/pdd2/MK64FN1M0LL12/system" -std=gnu11 -c -o "Sources\\Application.o" "..\\Sources\\Application.c" 
arm-none-eabi-gcc -mcpu=cortex-m4 -mthumb -mfloat-abi=hard -mfpu=fpv4-sp-d16 -O0 -fmessage-length=0 -fsigned-char -ffunction-sections -fdata-sections -Wall -g3 "-I..\\Generated_Code" -I../Sources -I../Project_Settings/Startup_Code "-IC:\\nxp\\KDS_3.2.0\\eclipse\\ProcessorExpert/lib/Kinetis/iofiles" "-IC:\\nxp\\KDS_3.2.0\\eclipse\\ProcessorExpert/lib/Kinetis/pdd/inc" "-IC:/Users/Erich Styger/Data/HSLU/Vorlesung/nemesis/CCE/Eck/KDS/FRDM_K64F_Fusion/Sources" "-IC:/Users/Erich Styger/Data/HSLU/Vorlesung/nemesis/CCE/Eck/KDS/FRDM_K64F_Fusion/Generated_Code" "-IC:\\nxp\\KDS_3.2.0\\eclipse\\ProcessorExpert/Repositories/Kinetis_Repository/lib/Kinetis/pdd2/MK64FN1M0LL12/system" -std=gnu11 -c -o "Sources\\main.o" "..\\Sources\\main.c" 
arm-none-eabi-gcc -mcpu=cortex-m4 -mthumb -mfloat-abi=hard -mfpu=fpv4-sp-d16 -O0 -fmessage-length=0 -fsigned-char -ffunction-sections -fdata-sections -Wall -g3 "-I..\\Generated_Code" -I../Sources -I../Project_Settings/Startup_Code "-IC:\\nxp\\KDS_3.2.0\\eclipse\\ProcessorExpert/lib/Kinetis/iofiles" "-IC:\\nxp\\KDS_3.2.0\\eclipse\\ProcessorExpert/lib/Kinetis/pdd/inc" "-IC:/Users/Erich Styger/Data/HSLU/Vorlesung/nemesis/CCE/Eck/KDS/FRDM_K64F_Fusion/Sources" "-IC:/Users/Erich Styger/Data/HSLU/Vorlesung/nemesis/CCE/Eck/KDS/FRDM_K64F_Fusion/Generated_Code" "-IC:\\nxp\\KDS_3.2.0\\eclipse\\ProcessorExpert/Repositories/Kinetis_Repository/lib/Kinetis/pdd2/MK64FN1M0LL12/system" -std=gnu11 -c -o "Sources\\Shell.o" "..\\Sources\\Shell.c" 

09:55:48 Build Finished (took 987ms)

In the screenshots I’m using NXP Kinetis Design Studio v3.2.0 which is Eclipse Luna based, but things should apply to any other Eclipse distribution.

The menus to build and clean selected files is only available if ‘Build Automatically’ is *not* enabled:

Eclipse Build Automatically is disabled

Eclipse Build Automatically disabled

This is a workspace setting under Window > Preferences:

Build Automatically Workspace Setting

Build Automatically Workspace Setting

Troubleshooting

There has been (and still are?) some Eclipse CDT glitches around this. I have seen cases on my system that sometimes the ‘Clean Selected Files(s)’ and ‘Build Selected File(s)’ are still grayed out. In that case:

  1. Verify that ‘Build automatically’ is disabled, both in the Project menu and in the workspace preferences. Change the setting to make sure it gets written to the settings, then restart Eclipse.
  2. Try with a new workspace, first with a ‘new’ project, then import your existing project into that new workspace and try it out. If this works, then it is probably a setting in your old/existing workspace. If somehow only works with the new workspace, you probably should go with the new workspace and import your existing project into it. I had this issue with a workspace I carried through different Eclipse versions.
  3. Make sure you select only files you can build, e.g. not a *.h file.

Summary

Building or cleaning only a few files which I select is a nice feature. It only works if ‘build automatically’ is disabled.

Happy Building 🙂

Advertisements

4 thoughts on “Build and Clean Selected Files in Eclipse CDT

  1. This is very useful! Do you know if there is a way to force a clean on a particular file every time a build is initiated? Ihave a file that embeds a time stamp using __TIME__ and would like an easy way to have that file always build. My current method deletes the .o in a prebuild step, but due to some Eclipse oddities it doesn’t always rebuild if using parallel compilation. Thanks!

    Like

What do you think?

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.