User forums > Using Code::Blocks

How to #define a header file name in Compiler settings?

(1/2) > >>

hanshuckebein:
Some of my source files contain lines like this:

   #include UART_CONFIG_H       // Symbol to be defined via compiler -D option

Defining the name under Build options | Compiler settings | #defines like this:

   UART_CONFIG_H="uart_config.h"

produces the following compiler invocation:

avr-gcc … -DUART_CONFIG_H="uart_config.h" -I. -I.. -I/usr/lib/avr/include -c ../uart-0.c -o obj/Release/uart-0.o

but this leads to a compiler error:

../uart-0.c:24:10: error: #include expects "FILENAME" or <FILENAME>

Why?

How to define UART_CONFIG_H in Build options | Compiler settings | #defines?

zainka:
Use -D
Add -D to the compiler followed by the define of interest
-DUART_CONFIG_H

An example i use (not complete but ). As you may see you can also pass a value

arm-none-eabi-gcc -c -DUSE_HAL_DRIVER -DUART_CONFIG_H -DSYSTEM_TIME=10

hanshuckebein:
Sorry, but that is no answer to my question. I want to know, how to do it via Build options | Compiler settings | #defines

stahta01:
I think you did the CB part right.

But you might need to change

--- Code: ---#include UART_CONFIG_H       // Symbol to be defined via compiler -D option

--- End code ---
To

--- Code: ---#include "UART_CONFIG_H"       // Symbol to be defined via compiler -D option

--- End code ---

If the above fails try defining in CB as


--- Code: ---UART_CONFIG_H="\"uart_config.h\""
--- End code ---

Tim S.

stahta01:
Looks like you need a C or C++ Macro expert to answer this question.

Because I can not get it to work using a #define statement in C; therefore I can not help you figure out what looks possibly impossible.

Tim S.

Navigation

[0] Message Index

[#] Next page

Go to full version