Getopt headers not found when building fresh app

I am having some trouble building a fresh new phoenix (1.2.1) app, at first the build was hanging getting dependencies (as described here Unable to compile phoenix project due to caching of dependencies)

After following the rebar3 workaround there I am seeing the following error:

===> Compiling pc
===> Fetching rebar3_hex ({pkg,<<"rebar3_hex">>,<<"3.1.0">>})
===> Downloaded package, caching at /Users/sam/.cache/rebar3/hex/default/packages/rebar3_hex-3.1.0.tar
===> Compiling rebar3_hex
===> Compiling fs
===> Compiling /Users/sam/phoenix/again3/deps/fs/c_src/mac/cli.c
===> /Users/sam/phoenix/again3/deps/fs/c_src/mac/cli.c:1:10: fatal error: 'getopt.h' file not found
#include <getopt.h>
1 error generated.

** (Mix) Could not compile dependency :fs, "/Users/sam/.mix/rebar3 bare compile --paths "/Users/sam/phoenix/again3/_build/dev/lib/*/ebin"" command failed. You can recompile this dependency with "mix deps.compile fs", update it with "mix deps.update fs" or clean it with "mix deps.clean fs"

The comment after the error (recompile / update / clean) didn’t seem to help

Elixir installed via homebrew, version 1.4.0 (erlang 19.2)

macOS 10.12.2 btw

Can you compile a C/C++ application that uses getopt? It seems like you are missing some very basic headers that should always be included with xcode. You do have xcode installed too yes (pretty sure I heard that is required when using homebrew, I don’t use Mac’s though ^.^)?

1 Like

I’m an iOS developer so I do have Xcode installed :smile:

I was able to track the issue down to having swiftenv settings for PATH (swiftenv is a version manager for swift so would make sense it might cause issues with accessing Xcode related files)

Have been able to build and run since, so all good :smile:


Hi. Can I have a bit more info on how to make it build, please? Thanks.

1 Like

Hi everyone, any news on this? Still happening to me when trying to start a simple server with mix phx.server created from scratch.

Elixir version: 1.8
Erlang OTP version: 21

macOs Mojave version: 10.14.2

Well, the news are, that it should work out of the box if you have xcode installed and do not mess around with include and library pathes.

At least that is what I understand from the posts above.

1 Like

I’ve tried to remove Xcode and install it from scratch and no luck either. I haven’t touched any includes or library paths that might make this happen.

Got any ideas as to why this might still happening?

I’m having the same problem here… Xcode installed and up to date, but file-watching fails when I start Phoenix.

Running mix deps.compile file_system generates errors:

18:58:33.406 [info]  Compiling file system watcher for Mac...
==> file_system
c_src/mac/cli.c:1:10: fatal error: 'getopt.h' file not found
#include <getopt.h>
1 error generated.
In file included from c_src/mac/compat.c:1:
c_src/mac/compat.h:16:10: fatal error: 'CoreServices/CoreServices.h' file not found
#include <CoreServices/CoreServices.h>
1 error generated.
In file included from c_src/mac/main.c:1:
c_src/mac/common.h:4:10: fatal error: 'CoreFoundation/CoreFoundation.h' file not found
#include <CoreFoundation/CoreFoundation.h>
1 error generated.

My googling of this error points to updating Xcode. Maybe I should try uninstalling Xcode completely and re-installing (?)

What version of OS X, Elixir, and file_system are you using?


OSX: 10.14.2
Elixir: 1.8
file_system: 0.8.2

@fireproofsocks tried that myself and no luck either…

OS 10.14.2 Mojave
Elixir 1.7.4 (compiled with Erlang/OTP 21)
file_system: 0.2.6 (from my mix.lock)

Hmmm, seems possibly related to OS 10.14 Mojave, I’m still on 10.13 but I will probably update soon. Can anyone confirm that file_system compiles for them on 10.14?

run open /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg
may fix this issue on MacOS 10.14


Thanks, that works!

With xcode and command line tools installed, where xcode would open fine w/o showing license page I still had the issue. Here were my steps:

run open /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg
get “file not found”

Run xcode-select --install, accept the license agreement and install the (new?) command line tools

run open /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg

^ NOTE that if you are on a different/future version of mac os you will probably have to change the 10.14 part in the above command to whatever version you’re on.

1 Like

/Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.15.pkg is not available in Catalina.

To fix it in Catalina, set the correct headers path in .bash_profile:
export SDKROOT="$(xcrun --sdk macosx --show-sdk-path)"

… and then recompile the deps.

1 Like

Catalina user here, I had some issues even after @bartblast solution, got this message:

clang-4.0: error: invalid version number in ‘-mmacosx-version-min=11.0’

so, the solution searching for the .sdk was right, but I had more than one version:

xxx@XXXMacbook file_system % ls /Applications/
DriverKit20.0.sdk       MacOSX.sdk              MacOSX11.0.sdk

I don’t know if it’s safe to just dump one of them, so I set manually the SDKROOT var to get "MacOSX.sdk " and it compiles fine now.