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?
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
Sorry, but that is no answer to my question. I want to know, how to do it via Build options | Compiler settings | #defines
I think you did the CB part right.
But you might need to change
#include UART_CONFIG_H // Symbol to be defined via compiler -D option
To
#include "UART_CONFIG_H" // Symbol to be defined via compiler -D option
If the above fails try defining in CB as
UART_CONFIG_H="\"uart_config.h\""
Tim S.
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.
Found example code that worked for what you wanted.
In CB I have this set
INCLUDE_FILE="stdlib.h"
Edit: The CB Define can also be done without the double quotes as in
INCLUDE_FILE=stdlib.h
and it still works.
The program code had this below.
#include <stdio.h>
#define STRINGIFY(X) STRINGIFY2(X)
#define STRINGIFY2(X) #X
#include STRINGIFY(INCLUDE_FILE)
int main()
{
printf("Hello world!\n");
return 0;
}
The shell is probably removing the "" from your string.
Try to use double or triple quotes.
Unfortunately we don't have a macro to preserve quotes. We only have REMOVE_QUOTES.
The other option seems to be to use escaping like \".
I'm not sure this is cross platform or if you need it to be cross platform.
@stahta01:
Your trick using STRINGIFY doesn't work with avr-gcc. This probably depends on the behavior of the c preprocessor and might be implementation dependent.
@oBFusCATed:
I tested several versions with double and triple " with and without preceding \ – nothing works. It seems to be impossible to define a double quoted -D macro. Also using ' to protect " doesn't help.
The only way I found, to do the trick is adding the folder which contains the header file to the -I options and define the macro as -DUART_CONFIG_H=<uart_config.h>, but that's not really conforming to the rules.
I found the solution:
-DUART_CONFIG_H=\\"uart_config.h\\"
We need a ESCAPE_QUOTES macro...