Adding Multiple Include Paths to Build Settings in Eclipse

In Eclipse and CDT, I need to tell the compiler where it has to search for the header files. The normal way is to go to the compiler settings (menu Project > Properties > C/C++ Build > Settings) and then add the include paths, one by one, using the ‘+’ icon:

Adding Include Path

Adding Include Path (shown using the GNU ARM Eclipse plugin)

But for many include paths, this is a time-consuming process. But there is another way.

Copy-Paste

The trick is that this ‘list of items’ control in the compiler settings work with copy and past shortcuts (CTRL-C and CTRL-V on Windows). This is especially useful if I have an existing project with all the paths setup: I can select (use CTRL to select multiple items individually, or CTRL-A (for all, on Windows) to select all items in the list:

Selected all Items

Selected all Items

Then press the host operating system shortcut for copy (CTRL-C on Windows), go to your destination panel and use the paste (CTRL-V on Windows) shortcut, and all the paths get copied. This approach works for all ‘list’ setting items, e.g. linker library settings.

💡 Unfortunately Eclipse does not show a context menu for the copy/paste operation in the settings panel. But you can use copy-paste for pretty much every setting, as long as you copy normal text.

Another trick is to use a clipboard viewer or a text file. As the format used is simple text list of items, it is possible to create a file or edit the items in a text editor:

clipboard items in text editor

clipboard items in text editor

That way I can use a script or anything I want to create that list of items, then copy-paste it into the settings.

Summary

Copy-Paste is a fast way to apply large sets of path (or list of items). That way I can easily copy settings from an existing project. Or I can create a list of folders in text file and then apply them all in one step. That way I can easily assign multiple items in a single step.

Happy Including 🙂

Advertisements

8 thoughts on “Adding Multiple Include Paths to Build Settings in Eclipse

  1. Pingback: Editing Compiler Include (or other) Settings in Eclipse | MCU on Eclipse

  2. Interesting. Just tried this for KDS3.01/win8.1 and didn’t work for me. Had to add lines one by one.
    Even tried copying into notepad, then copying into add include path.

    Like

  3. Hi Erich. I’m having troubles trying to add a folder to the compiler path. I’m using Kinetis Design Studio and I have created some drivers to use the gpio, tpm, etc. of a Kinetis device.This are .c and .h files, inside a folder with the name “drivers”. The problem is that if I follow your post, it appears that KDS is finding only my .h files, but not the.c files. I’m wondering if you know how I can solve this. I just want to create a folder with peripherals drivers and use it with all my projects.

    Thanks!!!!

    Like

    • Hi Juan,
      usually it is the other way around: the compiler finds the source (.c) files, but not the header (.h) files.
      The path to the .c files is passed to the compiler when compiling that file. But the paths to the header files is passed with the -I (include header search path/folder). So are you sure it does not find the .c files (and it is not about the .h files)? Can you post and details (e.g. the console log)?

      Like

      • Here are the errors in the console log:

        Building target: UART_Send.elf
        Invoking: Cross ARM C++ Linker
        arm-none-eabi-g++ -mcpu=cortex-m0plus -mthumb -O0 -fmessage-length=0 -fsigned-char -ffunction-sections -fdata-sections -g3 -T “MKL05Z32xxx4_flash.ld” -Xlinker –gc-sections -L”F:/Ejemplos_Libreria_KL05/UART_Send/Project_Settings/Linker_Files” -Wl,-Map,”UART_Send.map” -specs=nano.specs -specs=nosys.specs -o “UART_Send.elf” ./Sources/main.o ./Project_Settings/Startup_Code/startup_MKL05Z4.o ./Project_Settings/Startup_Code/system_MKL05Z4.o
        ./Sources/main.o: In function `main’:
        F:\Ejemplos_Libreria_KL05\UART_Send\Debug/../Sources/main.c:43: undefined reference to `CLK_init’
        makefile:52: recipe for target ‘UART_Send.elf’ failed
        F:\Ejemplos_Libreria_KL05\UART_Send\Debug/../Sources/main.c:48: undefined reference to `GPIO_Init’
        F:\Ejemplos_Libreria_KL05\UART_Send\Debug/../Sources/main.c:50: undefined reference to `GPIO_IO’
        F:\Ejemplos_Libreria_KL05\UART_Send\Debug/../Sources/main.c:53: undefined reference to `UART0_init’
        F:\Ejemplos_Libreria_KL05\UART_Send\Debug/../Sources/main.c:57: undefined reference to `UART0_putstr’
        F:\Ejemplos_Libreria_KL05\UART_Send\Debug/../Sources/main.c:58: undefined reference to `time_delay_ms’
        collect2.exe: error: ld returned 1 exit status
        make: *** [UART_Send.elf] Error 1

        At the top of my program I include the files like this:

        #include “clk.h”
        #include “lptmr.h”
        #include “gpio.h”
        #include “uart.h”

        And if I click on them holding the ctrl key, it takes me to those files, so I assume that KDS is finding the .h files, but not the .c files. But maybe I’m wrong.

        Thanks for your reply!

        Like

      • You need to add all the necessary sources files, e.g. where CLK_init(), GPIO_Init() etc are in to your project. The compiler has no way to magically find the .c source files for it.

        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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s