43

I recently bought a new MacBook on which I transferred my old session. Since then, and after i upgraded to 10.13, i can't get clang to compile anything including only iostream.
Given this program :

#include <iostream>

int main(void)
{
    std::cout << "Hello world !" << std::endl;
    return 0;
}

gives my this output when g++ main.cpp :

In file included from main.cpp:1:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/iostream:38:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/ios:216:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/__locale:15:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/string:470:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/string_view:171:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/__string:56:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/algorithm:640:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/memory:629:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/typeinfo:61:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/exception:82:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/cstdlib:86:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/stdlib.h:94:
In file included from /usr/include/stdlib.h:65:
In file included from /usr/include/sys/wait.h:110:
In file included from /usr/include/sys/resource.h:72:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/stdint.h:119:
In file included from /usr/local/include/stdint.h:82:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/inttypes.h:247:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/9.0.0/include/inttypes.h:30:
/usr/include/inttypes.h:235:8: error: unknown type name 'intmax_t'
extern intmax_t
       ^
/usr/include/inttypes.h:236:9: error: unknown type name 'intmax_t'
imaxabs(intmax_t j);
        ^
/usr/include/inttypes.h:240:2: error: unknown type name 'intmax_t'
        intmax_t quot;
        ^
/usr/include/inttypes.h:241:2: error: unknown type name 'intmax_t'
        intmax_t rem;
        ^
/usr/include/inttypes.h:246:9: error: unknown type name 'intmax_t'
imaxdiv(intmax_t __numer, intmax_t __denom);
        ^
/usr/include/inttypes.h:246:27: error: unknown type name 'intmax_t'
imaxdiv(intmax_t __numer, intmax_t __denom);
                          ^
/usr/include/inttypes.h:250:8: error: unknown type name 'intmax_t'
extern intmax_t
       ^
/usr/include/inttypes.h:256:8: error: unknown type name 'uintmax_t'; did you
      mean 'uintptr_t'?
extern uintmax_t
       ^
/usr/include/sys/_types/_uintptr_t.h:30:24: note: 'uintptr_t' declared here
typedef unsigned long           uintptr_t;
                                ^
In file included from main.cpp:1:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/iostream:38:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/ios:216:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/__locale:15:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/string:470:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/string_view:171:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/__string:56:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/algorithm:640:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/memory:629:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/typeinfo:61:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/exception:82:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/cstdlib:86:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/stdlib.h:94:
In file included from /usr/include/stdlib.h:65:
In file included from /usr/include/sys/wait.h:110:
In file included from /usr/include/sys/resource.h:72:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/stdint.h:119:
In file included from /usr/local/include/stdint.h:82:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/inttypes.h:247:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/9.0.0/include/inttypes.h:30:
/usr/include/inttypes.h:263:8: error: unknown type name 'intmax_t'
extern intmax_t
       ^
/usr/include/inttypes.h:269:8: error: unknown type name 'uintmax_t'; did you
      mean 'uintptr_t'?
extern uintmax_t
       ^
/usr/include/sys/_types/_uintptr_t.h:30:24: note: 'uintptr_t' declared here
typedef unsigned long           uintptr_t;
                                ^
In file included from main.cpp:1:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/iostream:38:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/ios:216:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/__locale:15:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/string:470:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/string_view:171:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/__string:56:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/algorithm:640:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/memory:629:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/typeinfo:61:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/exception:82:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/cstdlib:86:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/stdlib.h:94:
In file included from /usr/include/stdlib.h:65:
In file included from /usr/include/sys/wait.h:110:
/usr/include/sys/resource.h:197:2: error: unknown type name 'uint64_t'
        uint64_t ri_user_time;
        ^
/usr/include/sys/resource.h:198:2: error: unknown type name 'uint64_t'
        uint64_t ri_system_time;
        ^
/usr/include/sys/resource.h:199:2: error: unknown type name 'uint64_t'
        uint64_t ri_pkg_idle_wkups;
        ^
/usr/include/sys/resource.h:200:2: error: unknown type name 'uint64_t'
        uint64_t ri_interrupt_wkups;
        ^
/usr/include/sys/resource.h:201:2: error: unknown type name 'uint64_t'
        uint64_t ri_pageins;
        ^
/usr/include/sys/resource.h:202:2: error: unknown type name 'uint64_t'
        uint64_t ri_wired_size;
        ^
/usr/include/sys/resource.h:203:2: error: unknown type name 'uint64_t'
        uint64_t ri_resident_size;
        ^
/usr/include/sys/resource.h:204:2: error: unknown type name 'uint64_t'
        uint64_t ri_phys_footprint;
        ^
/usr/include/sys/resource.h:205:2: error: unknown type name 'uint64_t'
        uint64_t ri_proc_start_abstime;
        ^
fatal error: too many errors emitted, stopping now [-ferror-limit=]
20 errors generated.

I tried the following :

  • Reset CLT with Xcode-select --reset
  • Reinstall CLT
  • Reinstall Xcode

None of these solution worked and this starting to drive me crazy. Does somebody has the same problem and found a solution ?

EDIT : Xcode C++ Projects are successfully compiling, still don't understand why it would not in a terminal.

Marcadia
  • 538
  • 1
  • 4
  • 9
  • 1
    Sounds like `stdint.h` has slipped out of your search path. You've already ruled out a corrupt toolchain, the issue is likely a bad path in your project. You might try going through your settings and manually setting the compiler, linker search paths, etc. – Cinder Biscuits Oct 22 '17 at 12:32
  • I actually don't have such a project, I just want to test some features so I put all my code into a `main.cpp` file which I try to compile. One interesting thing to notice is that Xcode successfully build C++ projects (with `iostream` included) – Marcadia Oct 22 '17 at 13:15
  • i have similar issues when including stdlib in a C file. uintX_t types not found: file included from /usr/include/stdlib.h:65: In file included from /usr/include/sys/wait.h:110: /usr/include/sys/resource.h – j1nma Oct 27 '17 at 07:05

8 Answers8

102

I had exactly the same problem after transferring to macOS High Sierra (though, errors were not the same, but similar).

I found a workaround by renaming /usr/local/include to /usr/local/include_old (well, name does not really matter, just the fact that g++/clang will not search for headers in this folder anymore).

Stanislav Pankevich
  • 11,044
  • 8
  • 69
  • 129
Anton Malmygin
  • 3,406
  • 2
  • 25
  • 31
  • 2
    Nice! You can confirm this by running `cpp -v`. I still see `/usr/local/include` getting searched however as it's not there nothing is found anymore: `ignoring nonexistent directory "/usr/local/include"` – MrProper Jan 09 '18 at 18:31
  • 1
    It doesn't work for me ... now I have the following error: `undefined symbols for architecture x86_64:"_stdscr", referenced from` – Naive Developer Aug 26 '18 at 23:59
  • 1
    In case someone is trying to build Ruby gems with native extensions on Mac OS 10.15 and is getting a weird error referencing a C-lang `struct` fields in `resource.h`, this is what fixed the issue for me. – Dmytro Feb 26 '20 at 15:14
9

I had exactly the same problem today and after executing xcode-select --install, everything works fine!

supersize
  • 13,764
  • 18
  • 74
  • 133
8

I had the same issue after upgrading to MacOS Mojave 10.14.4 and Xcode 10.2

The issue got resolved, after installing the package /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg

Sudheer Hebbale
  • 421
  • 5
  • 11
  • 1
    You are referring to a file on your local file system. Are you sure this package is available on OP's system? – Mathyn Apr 03 '19 at 15:30
  • 1
    I believe this comes with the XCode installation, since it was also on my system in the exact same place. The other answers did not work for me, this was the only one that solved my problem. – rjferguson Apr 10 '19 at 19:25
  • Yes, the PKG file is created upon xcode-select --install – melMass Dec 13 '19 at 22:19
2

Same error I encountered on golang recently.

This was my solution: rm -rf /usr/local/include

I'm guessing the higher version of MacOS (I'm currently on BigSur) doesn't need that folder anymore so you might save a little bit of storage space if the folder is going to be deleted.

Pevin
  • 61
  • 2
1

I had a similar issue that after upgrading to high sierra (and Xcode 9.1) that my standard make reported unfamiliar warnings.

It drew .h files from /usr/local/include instead from the (as I thought) standard /usr/include. For example, there was no zlib.h available.

Reinstalling Xcode (who claims to install the commandline version too) did not help.

There was no /usr/include at all but the C++ system include were available through the links reported in clang --version, but none of the C-includes.

After xcode-select --install and actually "install" of the commandline material the /usr/include was populated with the necessary C libraries, and make started to compile without warnings again.

mpiffault
  • 431
  • 1
  • 6
  • 14
peter
  • 11
  • 1
1

Check that you don't include "/usr/local/include" into headers search path of your project.

Stoica Mircea
  • 782
  • 10
  • 22
1

The heavily upvoted answer here is to rename /usr/local/include to something else, which essentially removes it. This is not a great idea.

The source of this error is old header files in /usr/local/include that are no longer needed and create errors like the one OP describes.

Instead of removing this folder, clean it out.

  1. Move (not copy) all of the files in /usr/local/include into a backup location.
  2. (Optional) Reinstall any libraries you need on the system. In my case, I needed to reinstall GLFM and GLM because I'm doing some graphics programming.

Try building again.

Seth
  • 6,514
  • 5
  • 49
  • 58
0

Found the solution here, following @Sudheer's suggestion:

sudo installer -pkg /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg -target /

from https://donatstudios.com/MojaveMissingHeaderFiles

After renaming the /usr/local/include to /usr/local/include_old. Not sure if that was necessary, but renaming alone did not help (though it changed the kind of error I was getting).

Alex312
  • 36
  • 4