1

CS student, compiling worked fine before upgrading to Mojave. After doing so I cannot get anything to work if it has an include statment. For example:

#include <iostream>
int main()
{
    std::cout << "length:" << 10 << std::endl;

    return 0;
}

On compiling:

$ g++ -ferror-limit=3 main2.cpp -o test
In file included from main2.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:477:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/string_view:176:
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:642:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/utility:203:
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/cstdint:158:8: error: no member named 'uint8_t' in the global
      namespace
using::uint8_t;
     ~~^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/cstdint:159:8: error: no member named 'uint16_t' in the global
      namespace
using::uint16_t;
     ~~^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/cstdint:160:8: error: no member named 'uint32_t' in the global
      namespace
using::uint32_t;
     ~~^
fatal error: too many errors emitted, stopping now [-ferror-limit=]
4 errors generated.

I have

  • Installed Xcode 10
  • Installed the latest developer command line tools
  • I am on gcc 8.2 (the latest brew provides)
  • followed the suggestions here, which included running...

    open /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg
    
  • Restarted computer many times

Out of ideas. Compiling c++ from Xcode directly worked. But from command line g++ fails repeatedly. Not sure where to go next.

If relevant this is on MacBook Pro 15", 2018. MacOS 10.14.0.

Thanks for anyone's time.

Edit:

Using the information here I can compile some things using the

-isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk

flag in my g++ calls.

Of course I don't want to need to do this forever.

I have COMPLETELY removed Xcode 10 and devtools, and after reinstalling them the issue persists.

What else should I do here? How would it affect only me?

FINAL EDIT

Ended up reinstalling OS to solve issue. Was a big hammer for who knows how big of a nail, but it worked.

ktm
  • 124
  • 1
  • 8

2 Answers2

1

I had the same problem.

I had the headers installed in /Applications/.../MacOSX10.14.sdk/usr/include. Instead of aliasing my g++ calls to always use -isysroot, I added /Applications/.../MacOSX10.14.sdk/usr/include to my CPLUS_INCLUDE_PATH.

The exact line of code I used and added to my .bash_profile was

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

I feel that this is a more elegant solution, since from what I understand using isysroot or sysroot will tell g++ to not search in the default places, when you may need includes from both the mac SDK directory and the usual /usr/include, /usr/local/include, and so on.

mbwang
  • 21
  • 2
0

I believe there is an issue with the directories as the compiler can't find the iostream.h header file in the present working directory, and this might help Error: "no member named 'uint8_t' in the global namespace" on MacOS, though I am not sure.

JChat
  • 784
  • 2
  • 13
  • 33
  • 2
    I saw that post. It works. I'd prefer not to need to use `-isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk` everytime I compile, ya know? – ktm Sep 30 '18 at 20:35
  • 1
    There has never been an "iostream.h header file" in Standard C++, and if there were one, it would not be located in the current working directory. –  Sep 30 '18 at 21:45
  • That's why I pointed the user to a probable answer, which worked. By current working directory, I meant the directory in which C++ is installed/where the library files(header files) essential for executing the programming are located is missing being located by the compiler, that's why I wrote in my answer if you didn't read that completely, "I'm not sure". I'm sorry if this might have created an issue, but am glad that anyways, my answer could help the user resolve their problem. After all, this is the essence of stackoverflow, pointing out to probable answers if one isn't sure. Thanks! – JChat Oct 01 '18 at 08:14
  • Thanks for the tip @JoyjitChatterjee . It got me closer but still having major issues. Added an edit. – ktm Oct 01 '18 at 19:23