32

I am using macOS.

I am trying to build the code of mozilla-central.

While running the command ./mach build, the build fails at the compile step. Here are the relevant stack traces:

stack backtrace:
 0:20.24    0:        0x10436b5ff - std::sys::unix::backtrace::tracing::imp::unwind_backtrace::hed04c7a1477ef1e3
 0:20.24    1:        0x10434499d - std::sys_common::backtrace::print::h336400f22676933f
 0:20.24    2:        0x104373bd3 - std::panicking::default_hook::{{closure}}::h0d6700a02d682978
 0:20.24    3:        0x10437395c - std::panicking::default_hook::h90363c6d6ac04260
 0:20.24    4:        0x1043742fb - std::panicking::rust_panic_with_hook::h81c4f3add25e6667
 0:20.24    5:        0x1043740ce - std::panicking::continue_panic_fmt::hfa057b7c1de88179
 0:20.24    6:        0x104374020 - std::panicking::begin_panic_fmt::hd1123702300ea9f2
 0:20.24    7:        0x1035f4e6d - build_script_build::build_gecko::bindings::write_binding_file::h2d9a397b93e6a614
 0:20.24    8:        0x1035f651c - build_script_build::build_gecko::bindings::generate_bindings::ha066bc11b076e01d
 0:20.24    9:        0x1043808fe - __rust_maybe_catch_panic
 0:20.24   10:        0x1035eea9f - std::panicking::try::hcbd901ede6e8004c
 0:20.32   11:        0x1035e335c - <F as alloc::boxed::FnBox<A>>::call_box::h638a7c5eb8c94414
 0:20.33   12:        0x104373037 - std::sys_common::thread::start_thread::h78b1dd404be976ad
 0:20.33   13:        0x1043436c8 - std::sys::unix::thread::Thread::new::thread_start::h27c6becca8cf44e0
 0:20.33   14:     0x7fff636208cc - _pthread_body
 0:20.33   15:     0x7fff6362083e - _pthread_start
 0:20.33 /usr/local/Cellar/llvm/6.0.1/include/c++/v1/stdio.h:108:15: fatal error: 'stdio.h' file not found
 0:20.33 /usr/local/Cellar/llvm/6.0.1/include/c++/v1/stdio.h:108:15: fatal error: 'stdio.h' file not found, err: true
 0:20.37 thread '<unnamed>' panicked at 'Failed to generate bindings

According to me, the root cause is:

/usr/local/Cellar/llvm/6.0.1/include/c++/v1/stdio.h:108:15: fatal error: 'stdio.h' file not found, err: true

The solution listed online was to install xcode command line tools using:

xcode-select --install

I have already done this.

compor
  • 2,239
  • 1
  • 19
  • 29
97amarnathk
  • 957
  • 2
  • 11
  • 30

8 Answers8

66

Try setting SDKROOT explicitly to the system SDK:

export SDKROOT=$(xcrun --sdk macosx --show-sdk-path)

Doing it avoids the need for creating symlinks in /usr.

This error seem recurrent, for example, if you installed another compiler (e.g. gcc from brew). Setting SDKROOT became so common that it might be a good idea to add it to ~/.bash_profile.

F Pereira
  • 1,157
  • 10
  • 9
61

The root reason is due to a missing /usr/include directory.

Installing command-line tools (xcode-select --install), sometimes, will not automatically add it.

The Link shows the correct way: After installing command-line tools Install the package at:

# run this in Terminal
open /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg

After that,

you should have a directory /usr/include with header files

Mo...
  • 1,812
  • 2
  • 17
  • 22
Rick Li
  • 734
  • 6
  • 4
  • 3
    Note that `/usr/include` is deprecated and will eventually disappear. – Franklin Yu Dec 07 '19 at 23:31
  • 2
    This is the _only_ solution that has ever worked for me. How Apple can't get basic toolchaining correct with their flagship development environment (and haven't been able to for over a decade) is astounding. Thanks. – Qix - MONICA WAS MISTREATED Jan 25 '20 at 15:59
  • 1
    @Qix it’s those application authors who need to fix their source code. Apple made it very clear that this is deprecated. – Franklin Yu Mar 23 '20 at 02:34
  • @FranklinYu what exactly is deprecated? The default system paths should be set up correctly on a fresh install. There's no excuses here. – Qix - MONICA WAS MISTREATED Mar 27 '20 at 10:35
  • 1
    @Qix-MONICAWASMISTREATED Depending on library in `/usr/include` is deprecated. Application author should not assume anything there. And what do you mean by “correct”? Do you mean “same as Linux”? I might be wrong, but I don’t recall POSIX defines where libraries should be. Linux has FHS though. – Franklin Yu Mar 29 '20 at 04:23
  • there is a lot of spirited debate in these comments about how deprecated /usr/include is as a standard path, but as someone trying to set up an osx dev machine, I want to know what the standard path actually is rather than all the things that it is not. – Score_Under Oct 27 '21 at 02:14
  • This may also happen when you uninstall xcode (e.g. for upgrade...) – Ibrahim.H Aug 04 '22 at 22:19
  • I think this answer is obsolete because there is no directory `/Library/Developer/CommandLineTools/Packages` on MacOS 13.2.1. – Cameron Hudson Mar 25 '23 at 02:20
5

I had the same problem for compiling R packages, and running xcode-select --install and macOS_SDK_headers_for_macOS_10.14.pkg did not solve the problem.

I discovered that there seems to be some confusion from Apples side between macOS 10.14 and 10.15, since I'm running Mojave (10.14) with the latest xcode 11.0 (11A420a), and when clang compiles it looks for the MacOSX10.14.sdk sysroot directory in

/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/

but there only MacOSX10.15.sdk is present (along with other stuff). I fixed this with

pushd /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/ sudo ln -s MacOSX.sdk MacOSX10.14.sdk popd

Now I can install packages in RStudio again.

Jon
  • 163
  • 1
  • 8
3

This is a comment to Rick Li. It’s too long to fit into comment area.

The solution provided by Rick Li isn’t necessary the correct way. It’s only the easiest way. According to Xcode 10 release note:

…If you are the maintainer of such software, we encourage you to update your project to work with the SDK or file a bug report for issues that are preventing you from doing so. As a workaround, an extra package is provided which will install the headers to the base system. In a future release, this package will no longer be provided.

So the right way is to contact Mozilla team that their application won’t build without hack. It will break eventually.

If you don’t take this seriously, it would bite you in future. I still recall that Apple deprecated 32-bit application on macOS 10.13 (High Sierra). Now they formally disabled it in macOS 10.15 (Catalina) and I hear about people crying everywhere. Be responsible of your choice.

Lucas
  • 523
  • 2
  • 10
  • 20
Franklin Yu
  • 8,920
  • 6
  • 43
  • 57
2

I had the same problem. Tried to install the command-line tools via xcode-select --install but it didn't worked out for me.

After more research i found out that you can download the command-line tools on Apples official developer support site (Link)

Search for command and download first suggestion. Run the .dmg file and see if works.

Worked out great for me!

Phil
  • 21
  • 4
  • This does not really answer the question. If you have a different question, you can ask it by clicking [Ask Question](https://stackoverflow.com/questions/ask). You can also [add a bounty](https://stackoverflow.com/help/privileges/set-bounties) to draw more attention to this question once you have enough [reputation](https://stackoverflow.com/help/whats-reputation). - [From Review](/review/low-quality-posts/21635422) – Eric Brandt Dec 08 '18 at 21:41
  • 2
    why doesn't it answer the question. after that the stdio.h lib gets found – Phil Dec 08 '18 at 23:10
  • To clarify, you should search for the word "command" in Apple's search tool at the link provided. (I had thought the poster meant search for the command as in "stdio.h" and it was returning no results.) – Devon Mar 09 '23 at 12:16
0

I had the same problem (suddenly) compiling my own project - not finding <stdio.h> and <wchar.h>.

Running xcode-select --install said

xcode-select: error: command line tools are already installed, use "Software Update" to install updates

The following steps worked for me:

  1. Open Xcode once and allow it installing necessary components
  2. Remove the CMake cache files and retry cmake and build

I'm on macOS Big Sur 11.2.3 with Xcode version 12.5.

zhutq
  • 1
  • 1
0

Add -isysroot with needed MaсOSX version It work for me: MacOS Big Sure 11.4 & XCode 12.5.1

Know latest MacOS SDK version path by command:

xcrun --sdk macosx --show-sdk-path

Add path result to -isysroot:

-isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.3.sdk

UPD: if solution above did not help, try put -I to include from MacOS SDK

 -I$(MACOSSDK)/usr/include\
 -I$(MACOSSDK)/usr/include/c++\
 -I$(MACOSSDK)/usr/include/c++/v1\
 -I$(MACOSSDK)/usr/include/c++/v1/ext\

 -Wnonportable-include-path
Anonimys
  • 596
  • 1
  • 5
  • 14
-1

Command Line Tools Path Setting

I saw that "Command Line Tools" is not set in the xcode settings, as shown in the figure, click to select the Xcode path, and then compile, there is no such error.

  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Feb 01 '23 at 10:26