andrewz
andrewz

Reputation: 5220

iostream file not found error when compiling a precompile header in Xcode

I get a 'iostream' file not found error when compiling my Prefix.pch precompile header file in Xcode 9. It seems the compiler can't find it, yet it finds <stdio.h> and <Foundation/Foundation.h> files just fine.

#include <stdio.h> // ok
#include <iostream> // error
#import <Foundation/Foundation.h> // ok

[EDIT] The project is a mix of C++ and Objective-C files, and I am trying to pull into the .pch file some header files that are C++. I am unable to figure out how to mix the two in the .pch file.

Upvotes: 2

Views: 882

Answers (1)

zwcloud
zwcloud

Reputation: 4889

You should modify the pch with #ifdef preprocessor directives:

#ifdef __cplusplus
#include <cstdio>
#include <iostream>
#endif

#ifdef __OBJC__
#import <Foundation/Foundation.h>
#enid

(I just ran into this problem and solved it in this way.)

Upvotes: 2

Related Questions