Over a million developers have joined DZone.

Build and Clean Selected Files in Eclipse CDT

Are you working in a tight development spiral? You make changes to files that propagate to a massive project build. But you just need to verify that the files you're working on will build. Here's an easy way to do that.

· Java Zone

Check out this 8-step guide to see how you can increase your productivity by skipping slow application redeploys and by implementing application profiling, as you code! Brought to you in partnership with ZeroTurnaround.

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

The Java Zone is brought to you in partnership with ZeroTurnaround. Check out this 8-step guide to see how you can increase your productivity by skipping slow application redeploys and by implementing application profiling, as you code!

Topics:
eclipse ,ide ,build automation

Published at DZone with permission of Erich Styger, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

The best of DZone straight to your inbox.

SEE AN EXAMPLE
Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.
Subscribe

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}