Home / IOS Development / ios – XCode Build System: Clean up definitions of preprocessors and included header files?

ios – XCode Build System: Clean up definitions of preprocessors and included header files?



First question here.

I have some issues with the XCode Build System, especially with definitions of the processor.

7;m trying to define a macro that is used as part of a header file to choose which code to compile. The usual way to go would be to use #define CONFIG and then include the header on the next line. When the header is included, the macro is already defined and the header is configured accordingly.

But that’s where it’s starting to get weird!

The macro is not recognized at all, and the header is included as if #define statement was not there, so it fails #define CONFIG 1 and it is defined as 0 in header.h.

main.c

#define CONFIG 1
#include 
// From there:
//  - Build System: CONFIG is always 0, except if defined in build settings
//  - Clang (only): CONFIG is 1

header.h

#ifndef HEADER_H
#define HEADER_H

#if !defined(CONFIG)
#define CONFIG 0
#endif

#endif

The build system works as expected when the pre-processor macro is defined in the project build settings under “Apple Clang – Pre-processing”. It defines the global macro using -D parameter for clang make it available to all files used by the project.

However, the source code is compiled correctly when I use clang from a terminal using clang main.c.

Can anyone tell me what I need to configure for the building system to behave normally?

Thanks!


Source link