13

I just updated my MacBook Pro to macOS Catalina 10.15, and tried to compile and run a C++ command line program, but I had a problem which didn’t exist on previous versions;

This is simply the code:

#include <iostream>
using namespace std;

int main()
{
    cout << "Hello, World!\n";
    return 0;
}

The code compiles and outputs the expected, but still the Xcode says:

fatal error: 'iostream' file not found

I tried changing the Build Settings/C++ Standard Library to libstdc++, but a warning says:

warning: include path for stdlibc++ headers not found; pass '-stdlib=libc++' on the command line to use the libc++ standard library instead

And the same iostream error still exists.

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
zouabi
  • 649
  • 1
  • 7
  • 16

4 Answers4

3

I'm compiling from the command line, and none of the answers listed here (or elsewhere) worked for me.

What does seem to work (so far) is to add the following to .profile or whatever script your terminal uses to start up: (zsh, csh, bash, etc.)

export C_INCLUDE_PATH=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk/usr/include
export CPLUS_INCLUDE_PATH=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk/usr/include

You will probably have to change MacOSX10.15.sdk whenever you upgrade your operating system.

C_INCLUDE_PATH and CPLUS_INCLUDE_PATH are options for the clang toolchain rather than MacOS environment, so hopefully this solution will work long-term, unlike xcode-select --install (which won't fix the include directories on an upgrade) or ln -s ... /usr/include (which is now forbidden by System Integrity Protection).

John Perry
  • 2,497
  • 2
  • 19
  • 28
2

I had the same problem and used the following youtube video to fix it. https://www.youtube.com/watch?v=hrPm7tWC-BI&feature=youtu.be

or you can follow this path. Make sure to include the quotation marks

Project - Build Settings - Search Paths - Headers Search Paths, and add the following path: "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/"

Jonas
  • 31
  • 2
0

libstdc++ is not OK for Xcode Build & Compile time,

libstdc++ is OK for iPhone Run Time


From answer recommended by @Alan Birtles

libstdc++ Support was removed from the iOS 12.0 Simulator runtime, but it remains in the iOS 12.0 (device) runtime for binary compatibility with shipping apps.


I encountered this when declaration in .hpp file.

#include <iostream>
#include <string>

OK with

#ifdef __cplusplus

#include <iostream>
#include <string>

// usage code
#endif
dengApro
  • 3,848
  • 2
  • 27
  • 41
-1

I tried a fresh Catalina install with Xcode. I copied and pasted your code into "test.cpp" and then ran:

clang++ test.cpp

in the same directory as the "test.cpp" file from Terminal. The result was an "a.out" file which when run:

./a.out

output the required "Hello, World!" result. Hopefully that is of some use (as a point of reference).