cancel
Showing results for 
Search instead for 
Did you mean: 

Using -include file GCC option causes errors.

BobaJFET
Associate III

I have an STM32H743 project generated and i'd like to include an external file using the GCC "-include file" command option. I've added it as shown in this screenshot under C/C++ Build > settings > MCU/MPU GCC Compiler > Miscellaneous

BobaJFET_0-1738262058529.png

The problem is the compiler doesn't seem to find file.c, no matter where I place it within the project directory. I've tried placing inside the same folder as main.c with no success. 

Here's a good reference to where this option comes from. 

Preprocessor Options (Using the GNU Compiler Collection (GCC))

The error:

<command-line>: fatal error: file.c: No such file or directory
compilation terminated.

 

Update: I think i've figured out how to get it to know where the file is, by adding the path under C/C++ General > Paths and Symbols > Source Location. But I still have these make errors: 

make: *** [Drivers/STM32H7xx_HAL_Driver/Src/subdir.mk:88: Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal.o] Error 1
make: *** [Drivers/STM32H7xx_HAL_Driver/Src/subdir.mk:88: Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_adc.o] Error 1
make: *** [Drivers/STM32H7xx_HAL_Driver/Src/subdir.mk:88: Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_adc_ex.o] Error 1
make: *** [Drivers/STM32H7xx_HAL_Driver/Src/subdir.mk:88: Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_cortex.o] Error 1
make: *** [Drivers/STM32H7xx_HAL_Driver/Src/subdir.mk:88: Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_dma.o] Error 1
make: *** [Drivers/STM32H7xx_HAL_Driver/Src/subdir.mk:88: Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_dma_ex.o] Error 1
make: *** [Drivers/STM32H7xx_HAL_Driver/Src/subdir.mk:88: Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_exti.o] Error 1
make: *** [Drivers/STM32H7xx_HAL_Driver/Src/subdir.mk:88: Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_flash.o] Error 1

 

I've used this -include option in other IDE's before with no problems but i'm a bit new to cubeIDE.

 

 

10 REPLIES 10

@TDK wrote:

Source folders include source (*.c) files. The compiler will compile all source files found within the source folders.

That's not quite true.

So-called "source" and "include" folders are a property of the IDE Project - not the Compiler.

By configuring a "source" folder in your Project you are saying to the IDE, "I want all the source files in this folder to be compiled when I press the 'Build' button"

Similarly, the "Include Paths" are an IDE Project property which says to the IDE, "tell the Compiler that these are where it should look to find any #included files"

The IDE then takes care of generating the appropriate Compiler commands to do that - in the case of CubeIDE, it creates one compiler command line for each source file.

Each of those compiler command lines will have -I options for all of the entries in the Project's Include Paths list:

https://gcc.gnu.org/onlinedocs/gcc/Directory-Options.html#:~:text=Add%20the%20directory%20dir%20to%20the%20list%20of%20directories%20to%20be%20searched%20for%20header%20files%20during%20preprocessing

 

CubeIDE itself doesn't have any concept of "include folders" - it just has its list of Include Paths.

 

PS:

@BobaJFET because you've asked for your file.c to be treated as an Include file, it will have to be in a location covered by your Projects Include Paths.

You'll probably also have to ensure that it does not get separately compiled ...

 

PPS:

In CubeIDE (ie, Eclipse) a Source folder is identified by 'C' on its icon; eg,

AndrewNeil_0-1738494909547.png