2

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.

andrewz
  • 4,729
  • 5
  • 49
  • 67
  • Are you building a C++ source file? Or a C source file? Can you please copy the complete and full output (as text) and paste it into the question? It should include the file-name which should give us (and you!) some hint about that. – Some programmer dude Dec 07 '17 at 12:45
  • This is a precompile header file, a `.pch` file. – andrewz Dec 07 '17 at 12:47
  • You still need to copy-paste the full and complete output. – Some programmer dude Dec 07 '17 at 12:54
  • Actually, that `#import` thing could give a hint: It's part of Objective-C (or Objective-C++). My ***guess*** is that you're building an Objective-**C** project, not Objective-C++. – Some programmer dude Dec 07 '17 at 12:54
  • I don't have text output of compilation. I am compiling in Xcode. I have output displayed in the issue navigator. The error is: `'iosstream' file not found` in Prefix.pch – andrewz Dec 07 '17 at 16:03
  • Possible duplicate of [iostream.h, fstream.h cannot be found](https://stackoverflow.com/questions/2225277/iostream-h-fstream-h-cannot-be-found) – rptwsthi Nov 16 '18 at 08:05

1 Answers1

2

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.)

zwcloud
  • 4,546
  • 3
  • 40
  • 69