User forums > Using Code::Blocks
How to #define a header file name in Compiler settings?
stahta01:
Found example code that worked for what you wanted.
In CB I have this set
--- Code: ---INCLUDE_FILE="stdlib.h"
--- End code ---
Edit: The CB Define can also be done without the double quotes as in
--- Code: ---INCLUDE_FILE=stdlib.h
--- End code ---
and it still works.
The program code had this below.
--- Code: ---#include <stdio.h>
#define STRINGIFY(X) STRINGIFY2(X)
#define STRINGIFY2(X) #X
#include STRINGIFY(INCLUDE_FILE)
int main()
{
printf("Hello world!\n");
return 0;
}
--- End code ---
oBFusCATed:
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.
hanshuckebein:
@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.
hanshuckebein:
I found the solution:
-DUART_CONFIG_H=\\"uart_config.h\\"
oBFusCATed:
We need a ESCAPE_QUOTES macro...
Navigation
[0] Message Index
[*] Previous page
Go to full version