XCode Build System: Messing up preprocessors definitions and included header files?


First question here.

I have some troubles with the XCode Build System, specifically with preprocessor definitions.

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

But that’s where it starts to get weird!

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


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


#ifndef HEADER_H
#define HEADER_H

#if !defined(CONFIG)
#define CONFIG 0


The build system acts as expected when the preprocessor macro is defined in the project build settings under the "Apple Clang – Preprocessing" section. It defines the global macro using the -D parameter of clang making it available to any files used by the project.

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

Could someone tell me what I need to configure for the build system to behave normally?


Source: Ios Questions

Categorised as c++, ios, macos, xcode, xcodebuild Tagged , , , ,


Leave a Reply

Your email address will not be published. Required fields are marked *

Still Have Questions?

Our dedicated development team is here for you!

We can help you find answers to your question for as low as 5$.

Contact Us