4

I have used the g++ command on the terminal to compile C++ programs but all of a sudden, after an update to my Mac's OS (to macOS 13.3 Ventura,), I started receiving the message:

againtest.c:6:10: fatal error: stdio.h: No such file or directory
#include <stdio.h>
     ^~~~~~~~~
compilation terminated.

Then I reinstalled Xcode by Xcode-select --install , trying to reset the environment -- nothing works and I reinstalled command line tools and that did not solve the problem that include file is missing.

Later I tried to make it work by:

export CPATH='/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platf>
export LIBRARY_PATH='/Applications/Xcode.app/Contents/Developer/Platforms/MacOS>

My Clion works well but on terminal, it still doesn't work. If I attempt to compile a simple program like that:

#include<iostream>
using namespace std;

int main() {
    int a = 0;
    while(a++ < 10)
        cout << a << endl;
    return 0;
}
─$ g++ while.cpp 
In file included from while.cpp:1:
In file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/v1/iostream:41:
In file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/v1/ios:221:
In file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/v1/__locale:18:
In file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/v1/memory:841:
In file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/v1/__algorithm/copy.h:12:
In file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/v1/__algorithm/unwrap_iter.h:13:
In file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/v1/__iterator/iterator_traits.h:14:
In file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/v1/__iterator/incrementable_traits.h:15:
In file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/v1/concepts:133:
In file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/v1/__concepts/arithmetic.h:15:
In file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/v1/type_traits:421:
In file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/v1/__functional/invoke.h:15:
In file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/v1/__type_traits/apply_cv.h:16:
In file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/v1/__type_traits/remove_reference.h:13:
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/v1/cstddef:50:9: error: no member named 'nullptr_t' in the global namespace
using ::nullptr_t;
      ~~^
In file included from while.cpp:1:
In file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/v1/iostream:41:
In file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/v1/ios:221:
In file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/v1/__locale:18:
In file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/v1/memory:841:
In file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/v1/__algorithm/copy.h:12:
In file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/v1/__algorithm/unwrap_iter.h:13:
In file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/v1/__iterator/iterator_traits.h:14:
In file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/v1/__iterator/incrementable_traits.h:15:
In file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/v1/concepts:133:
In file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/v1/__concepts/arithmetic.h:15:
In file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/v1/type_traits:452:
In file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/v1/__type_traits/is_compound.h:14:
In file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/v1/__type_traits/is_fundamental.h:14:
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/v1/__type_traits/is_null_pointer.h:24:49: error: use of undeclared identifier 'nullptr_t'
template <>          struct __is_nullptr_t_impl<nullptr_t> : public true_type {};
                                                ^
In file included from while.cpp:1:
In file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/v1/iostream:41:
In file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/v1/ios:221:
In file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/v1/__locale:18:
In file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/v1/memory:848:
In file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/v1/__memory/allocator.h:18:
In file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/v1/new:94:
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/v1/exception:149:45: error: field has incomplete type 'std::exception_ptr'
    _LIBCPP_INLINE_VISIBILITY exception_ptr(nullptr_t) _NOEXCEPT : __ptr_() {}
                                            ^
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/v1/exception:144:24: note: definition of 'std::exception_ptr' is not complete until the closing '}'
class _LIBCPP_TYPE_VIS exception_ptr
                       ^
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/v1/exception:149:5: error: '__abi_tag__' attribute only applies to structs, variables, functions, and namespaces
    _LIBCPP_INLINE_VISIBILITY exception_ptr(nullptr_t) _NOEXCEPT : __ptr_() {}
    ^
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/v1/__config:689:37: note: expanded from macro '_LIBCPP_INLINE_VISIBILITY'
#  define _LIBCPP_INLINE_VISIBILITY _LIBCPP_HIDE_FROM_ABI
                                    ^
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/v1/__config:673:26: note: expanded from macro '_LIBCPP_HIDE_FROM_ABI'
          __attribute__((__abi_tag__(_LIBCPP_TOSTRING(_LIBCPP_VERSIONED_IDENTIFIER))))
                         ^
In file included from while.cpp:1:
In file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/v1/iostream:41:
In file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/v1/ios:221:
In file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/v1/__locale:18:
In file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/v1/memory:848:
In file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/v1/__memory/allocator.h:18:
In file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/v1/new:94:
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/v1/exception:149:55: error: expected ';' at end of declaration list
    _LIBCPP_INLINE_VISIBILITY exception_ptr(nullptr_t) _NOEXCEPT : __ptr_() {}
                                                      ^
In file included from while.cpp:1:
In file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/v1/iostream:41:
In file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/v1/ios:221:
In file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/v1/__locale:18:
In file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/v1/memory:860:
In file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/v1/__memory/shared_ptr.h:28:
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/v1/__memory/unique_ptr.h:173:32: error: member 'nullptr_t' declared as a template
  _LIBCPP_CONSTEXPR unique_ptr(nullptr_t) _NOEXCEPT : __ptr_(__value_init_tag(), __value_init_tag()) {}
                               ^
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/v1/__memory/unique_ptr.h:173:42: error: expected ';' at end of declaration list
  _LIBCPP_CONSTEXPR unique_ptr(nullptr_t) _NOEXCEPT : __ptr_(__value_init_tag(), __value_init_tag()) {}
                                         ^
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/v1/__memory/unique_ptr.h:262:25: error: unknown type name 'nullptr_t'
  unique_ptr& operator=(nullptr_t) _NOEXCEPT {
                        ^
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/v1/__memory/unique_ptr.h:395:32: error: member 'nullptr_t' declared as a template
  _LIBCPP_CONSTEXPR unique_ptr(nullptr_t) _NOEXCEPT : __ptr_(__value_init_tag(), __value_init_tag()) {}
                               ^
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/v1/__memory/unique_ptr.h:395:42: error: expected ';' at end of declaration list
  _LIBCPP_CONSTEXPR unique_ptr(nullptr_t) _NOEXCEPT : __ptr_(__value_init_tag(), __value_init_tag()) {}
                                         ^
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/v1/__memory/unique_ptr.h:484:25: error: unknown type name 'nullptr_t'
  unique_ptr& operator=(nullptr_t) _NOEXCEPT {
                        ^
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/v1/__memory/unique_ptr.h:533:14: error: unknown type name 'nullptr_t'
  void reset(nullptr_t = nullptr) _NOEXCEPT {
             ^
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/v1/__memory/unique_ptr.h:533:24: error: cannot initialize a parameter of type 'int' with an rvalue of type 'std::nullptr_t'
  void reset(nullptr_t = nullptr) _NOEXCEPT {
                       ^ ~~~~~~~
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/v1/__memory/unique_ptr.h:533:24: note: passing argument to parameter here
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/v1/__memory/unique_ptr.h:594:45: error: unknown type name 'nullptr_t'
operator==(const unique_ptr<_T1, _D1>& __x, nullptr_t) _NOEXCEPT
                                            ^
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/v1/__memory/unique_ptr.h:602:12: error: unknown type name 'nullptr_t'
operator==(nullptr_t, const unique_ptr<_T1, _D1>& __x) _NOEXCEPT
           ^
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/v1/__memory/unique_ptr.h:610:45: error: unknown type name 'nullptr_t'
operator!=(const unique_ptr<_T1, _D1>& __x, nullptr_t) _NOEXCEPT
                                            ^
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/v1/__memory/unique_ptr.h:618:12: error: unknown type name 'nullptr_t'
operator!=(nullptr_t, const unique_ptr<_T1, _D1>& __x) _NOEXCEPT
           ^
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/v1/__memory/unique_ptr.h:626:44: error: unknown type name 'nullptr_t'
operator<(const unique_ptr<_T1, _D1>& __x, nullptr_t)
                                           ^
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/v1/__memory/unique_ptr.h:635:11: error: unknown type name 'nullptr_t'
operator<(nullptr_t, const unique_ptr<_T1, _D1>& __x)
          ^
fatal error: too many errors emitted, stopping now [-ferror-limit=]
20 errors generated.

Would like some help on this.

2

4 Answers 4

2

We have the same issue and fixed with this:

  • Run Xcode.app
  • Delete SDK 13.3 and use 12.3 instead
  • Do xcode-select --install and continue to work on your project
2
  • I'm so glad to hear that downgrading allows you to continue working! This bug has stopped my own development in its tracks. Unf. if you're trying to target the latest versions of Ventura (macos 13.3) using SDK 13.3 seems to the only way (per guidelines on this page: developer.apple.com/support/xcode ) I'm crossing my fingers for a real fix from Apple (and have submitted the issue via the Feedback Reporter tool) but grateful for the workaround you found!
    – Dave
    Apr 30, 2023 at 17:20
  • also, see my answer below for how I solved the issue
    – Dave
    May 6, 2023 at 19:59
2

I was having this issue and finally tracked it down to an environment variable that was set in my environment.

The variable is

CPLUS_INCLUDE_PATH

I had previously followed the workaround described here which involved setting an environment variable (in my bash .profile) :

CPLUS_INCLUDE_PATH=/usr/local/opt/llvm/include/c++/v1:/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include

Removing the CPLUS_INCLUDE_PATH environment variable fixed the problem and compilation works again.

Hopefully this will help someone else get past this tricky/subtle build problem!

If not, "eskimo" on the Apple Developer forums offered some helpful diagnostic suggestions when I posted this issue on the Apple Developer Forum. Maybe those would be of use.

The diagnostic commands he requested I run were the following :

  • sw_vers
  • xcode-select -p (to show setting)
  • xcode-select -s /Library/Developer/CommandLineTools (to set setting)
  • csrutil status
  • pkgutil --pkgs
  • printenv | \grep CPLUS_INCLUDE_PATH (my own addition)

The results of these commands might be helpful for someone to help you, if you continue to have problems.

2
  • 1
    Apple Developers forums are available to everybody, registered or not.
    – Thinkr
    May 3, 2023 at 9:30
  • @Thinkr Thank you for the info and thoughtful edits!
    – Dave
    May 4, 2023 at 18:04
2

MacOS Ventura 13.5
Found and tried many different solutions for multiple hours. NO need to update brew, (re)install gcc, (re)install XCode, run xcode-select --install, or edit the Makevars file.

What helped was removing the problematic directory from the Terminal

cd /Library/Developer/CommandLineTools/SDKs
rm -rf MacOSX.sdk

If you are unsure, you can rename the directory, instead of deleting it

cd /Library/Developer/CommandLineTools/SDKs
sudo mv MacOSX.sdk MacOSX_old.sdk

However, running the ln -s suggested above did not help!

1
  • You are right, I am on Ventura M2. Running rm -rf MacOSX.sdk is enough. If one already link the file with ln -s MacOSX13.3.sdk MacOSX.sdk or something like that, just unlink it with rm -rf MacOSX.sdk again and it is good to go.
    – James H.
    Sep 15, 2023 at 15:20
1

In my case I did not have xcode install, so I followed the path to commandlinetools/sdks and created a new link to 12.3 sdk to make it work:

cd /Library/Developer/CommandLineTools
rm -rf MacOSX.sdk
ln -s MacOSX12.3.sdk MacOSX.sdk

Dont need to run xcode-select --install

Hope it helps!

2
  • Man, you are a lifesaver. It works, but in my case, except to rm -rf MacOSX.sdk, I had to call also rm -rf MacOSX13.3.sdk.
    – miso01
    Apr 30, 2023 at 9:05
  • I'm so glad to hear that downgrading allows you to continue working! This bug has stopped my own development in its tracks. Unf. if you're trying to target the latest versions of Ventura (macos 13.3) using SDK 13.3 seems to the only way (per guidelines on this page: developer.apple.com/support/xcode ) I'm crossing my fingers for a real fix from Apple (and have submitted the issue via the Feedback Reporter tool) but grateful for the workaround you found! See my own answer here for how I was able to get around this and continue with the latest and 'greatest' sdk
    – Dave
    May 6, 2023 at 20:00

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .