Big Sur clang "invalid version" error due to MACOSX_DEPLOYMENT_TARGET
Asked Answered
L

8

60

I assume due to the fact Big Sur is sparkling new hotfixes for the new OS have not yet happen. When attempting to install modules that use clang for compilation, the following error is thrown:

clang: error: invalid version number in 'MACOSX_DEPLOYMENT_TARGET=11.0'

Currently running:

  • Mac OS Big Sur, 11.0 Beta
  • Intel CPU (i386)
  • Python 3.8.0 installed via pyenv

Multiple modules have clang dependencies, and so it seems this error is quite common. An example:

pip install multidict

Installing older versions of Command Line Tools (e.g. 11.5) does not work as well.

Loux answered 19/9, 2020 at 18:32 Comment(0)
L
63

Figure out the issue on my end.

Previously I had installed XCode from the App Store (11.7) and set its SDKs as my default:

sudo xcode-select --switch /Applications/Xcode.app/

However, it seems this come with an unsupported version of clang:

  λ clang --version
Apple clang version 11.0.3 (clang-1103.0.32.62)
Target: x86_64-apple-darwin20.1.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin

Setting the xcode-select to the latest version via:

sudo xcode-select --switch /Library/Developer/CommandLineTools

EDIT (11/15/2020)

You might receive an error when attempting the above change:

xcode-select: error: invalid developer directory '/Library/Developer/CommandLineTools'

To fix this, you must install the latest Command Line Tools from the official Apple website here. At the time of writting this edit, I installed the Command Line Tools for Xcode 12.3 beta.

Changes clang to a working version:

  λ clang --version
Apple clang version 12.0.0 (clang-1200.0.32.2)
Target: x86_64-apple-darwin20.1.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin

The built-in Big Sur SDK is version 10.15, which seems to work without an issue:

  λ ls /Library/Developer/CommandLineTools/SDKs
MacOSX.sdk      MacOSX10.15.sdk

After the switch, multidict was installed successfully.

  λ pip install multidict
Collecting multidict
  Downloading multidict-4.7.6-cp38-cp38-macosx_10_14_x86_64.whl (48 kB)
     |████████████████████████████████| 48 kB 589 kB/s
Installing collected packages: multidict
Successfully installed multidict-4.7.6

Further investigation seems to indicate this is a design choice by Apple (source):

enter image description here

Therefore, ensuring your SDK is the default out-of-the-box as opposed to XCode's new SDK should be enough for the system to switch context when needed (and seems to work fine with pip+clang).

Loux answered 19/9, 2020 at 19:21 Comment(0)
A
88

I would like to extend @Felipe excellent answer; if it doesn't work even with running

>>> softwareupdate --all --install --force
Software Update Tool

Finding available software
No updates are available.

...following the wisdom of the "homebrew doctor" solves it, i.e. remove and reinstall:

sudo rm -rf /Library/Developer/CommandLineTools
sudo xcode-select --install
Allowance answered 14/11, 2020 at 21:35 Comment(4)
Great find. Thank you for reminding me to update my answer- since then, Apple now requires users to install the latest version of the Xcode Command Line Tools from their website. Updated for anyone else looking into the answer.Loux
The second part of the answer fixed it for me.Eiland
the sceond part worked for me but then I had to re-switch the xcode-select sudo xcode-select --switch /Library/Developer/CommandLineToolsBourbonism
You're a lifesaver! I dunno why it was so hard to find the answer to this problem.Shied
L
63

Figure out the issue on my end.

Previously I had installed XCode from the App Store (11.7) and set its SDKs as my default:

sudo xcode-select --switch /Applications/Xcode.app/

However, it seems this come with an unsupported version of clang:

  λ clang --version
Apple clang version 11.0.3 (clang-1103.0.32.62)
Target: x86_64-apple-darwin20.1.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin

Setting the xcode-select to the latest version via:

sudo xcode-select --switch /Library/Developer/CommandLineTools

EDIT (11/15/2020)

You might receive an error when attempting the above change:

xcode-select: error: invalid developer directory '/Library/Developer/CommandLineTools'

To fix this, you must install the latest Command Line Tools from the official Apple website here. At the time of writting this edit, I installed the Command Line Tools for Xcode 12.3 beta.

Changes clang to a working version:

  λ clang --version
Apple clang version 12.0.0 (clang-1200.0.32.2)
Target: x86_64-apple-darwin20.1.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin

The built-in Big Sur SDK is version 10.15, which seems to work without an issue:

  λ ls /Library/Developer/CommandLineTools/SDKs
MacOSX.sdk      MacOSX10.15.sdk

After the switch, multidict was installed successfully.

  λ pip install multidict
Collecting multidict
  Downloading multidict-4.7.6-cp38-cp38-macosx_10_14_x86_64.whl (48 kB)
     |████████████████████████████████| 48 kB 589 kB/s
Installing collected packages: multidict
Successfully installed multidict-4.7.6

Further investigation seems to indicate this is a design choice by Apple (source):

enter image description here

Therefore, ensuring your SDK is the default out-of-the-box as opposed to XCode's new SDK should be enough for the system to switch context when needed (and seems to work fine with pip+clang).

Loux answered 19/9, 2020 at 19:21 Comment(0)
E
27

I had already removed and reinstalled xtools CLI, but the error persisted..

All I needed to do was

export SYSTEM_VERSION_COMPAT=1

then the error went away.

"SYSTEM_VERSION_COMPAT" is an environment variable which macOS utilities and 3rd-parties use to determine how they behave when running on newer versions of macOS, i.e. to allow backwards compatibility or not. It is often used by devs and does not guarantee an app will function normally.

its value ranges from unset, 0 (disable) and 1 (enable). Default value varies across OS version. While with little impact, it is good practice to confirm/backup your system's existing setting before changing this value.

Euhemerus answered 11/12, 2020 at 3:34 Comment(2)
I was using pipenv install then it spit a ton of error and warning in the console, then after set this, it works like charm and all the dependencies are installed/resolved smoothly. This saved my day! ThanksGeorganngeorge
@user8076929 your edit is very useful. Does that information come from somewhere online (e.g. can a link/source be included?)Euhemerus
S
24

in my case I had to remove /Library/Developer/CommandLineTools and re-install command line tools

% sudo rm -rf /Library/Developer/CommandLineTools
% sudo xcode-select --install
% clang --version
Apple clang version 12.0.0 (clang-1200.0.32.27)
Target: x86_64-apple-darwin20.1.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin
Sitology answered 1/12, 2020 at 16:22 Comment(3)
Thanks! I had clang 11.0.3, but macOS "Software Update" did not update it. Deleting and reinstalling worked.Krimmer
god bless you!!!Gilpin
If you installed Xcode, sudo xcode-select --switch /Applications/Xcode.app is preferred to sudo xcode-select --installVegetal
I
5

In my case removing CLT and LLVM and setting XCode just compiled.

% sudo rm -rf /Library/Developer/CommandLineTools
% sudo xcode-select --switch /Applications/Xcode.app
% brew uninstall llvm # if installed via brew
% clang --version
Apple clang version 12.0.0 (clang-1200.0.32.28)
Target: x86_64-apple-darwin20.2.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin

gcc and g++ now compiling without any error.

Isonomy answered 27/12, 2020 at 1:33 Comment(0)
L
3

For my case, to be safe, I renamed the existing directory and reinstalled the latest one. The "clang" build error is gone right after the update.

Before:

$ clang --version
Apple clang version 11.0.3 (clang-1103.0.32.62)
Target: x86_64-apple-darwin21.4.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools

Action:

sudo mv /Library/Developer/CommandLineTools /Library/Developer/CommandLineTools.old
sudo xcode-select --install

After:

$ clang --version
Apple clang version 13.0.0 (clang-1300.0.27.3)
Target: x86_64-apple-darwin21.4.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin
Lananna answered 20/4, 2022 at 22:28 Comment(0)
A
0

macOS Monterey 12.3.2 failed to install a new version of python.

$ pyenv install 3.8.4

found it was due to a bug in the latest version of Monterey as MACOSX_DEPLOYMENT_TARGET was previously set to 12.3.

Fixed it by setting MACOSX_DEPLOYMENT_TARGET=12.3.0

% pyenv install 3.8.4
python-build: use [email protected] from homebrew
python-build: use readline from homebrew
Downloading Python-3.8.4.tar.xz...
-> https://www.python.org/ftp/python/3.8.4/Python-3.8.4.tar.xz
Installing Python-3.8.4...
patching file Misc/NEWS.d/next/Build/2021-10-11-16-27-38.bpo-45405.iSfdW5.rst
patching file configure
patching file configure.ac
python-build: use tcl-tk from homebrew
python-build: use readline from homebrew
python-build: use zlib from xcode sdk

BUILD FAILED (OS X 12.3.1 using python-build 20180424)

Inspect or clean up the working tree at /var/folders/5r/61nxx8hs53x6hhzm_r86jhjrq0r6qq/T/python-build.20220504193655.2344
Results logged to /var/folders/5r/61nxx8hs53x6hhzm_r86jhjrq0r6qq/T/python-build.20220504193655.2344.log

Last 10 log lines:
checking for python3... python3
checking for --enable-universalsdk... no
checking for --with-universal-archs... no
checking MACHDEP... "darwin"
checking for gcc... clang
checking whether the C compiler works... no
configure: error: in `/var/folders/5r/61nxx8hs53x6hhzm_r86jhjrq0r6qq/T/python-build.20220504193655.2344/Python-3.8.4':
configure: error: C compiler cannot create executables
See `config.log' for more details
make: *** No targets specified and no makefile found.  Stop.

After fix:

 % pyenv install 3.8.4
python-build: use [email protected] from homebrew
python-build: use readline from homebrew
Downloading Python-3.8.4.tar.xz...
-> https://www.python.org/ftp/python/3.8.4/Python-3.8.4.tar.xz
Installing Python-3.8.4...
patching file Misc/NEWS.d/next/Build/2021-10-11-16-27-38.bpo-45405.iSfdW5.rst
patching file configure
patching file configure.ac
python-build: use tcl-tk from homebrew
python-build: use readline from homebrew
python-build: use zlib from xcode sdk
Installed Python-3.8.4 to /Users/{USER}/.pyenv/versions/3.8.4
Anthurium answered 4/5, 2022 at 20:2 Comment(0)
L
0

I had a slightly different issue, while trying to build Qt WebEngine 6.5 on an iMac m1. For me, the error was

error: invalid version number in 'MACOSX_DEPLOYMENT_TARGET='

I tried what was suggested, but while it had fixed this issue, the following steps failed because Qt was complaining about having a Command Line Tools instance only, unable to find Xcode.

I solved by simply setting a value to it :

export MACOSX_DEPLOYMENT_TARGET=11

Context : iMac m1 (arm64 chip), macOS Ventura 13.4, XCode 14.3, Qt Webengine 6.5.1

Livia answered 29/6, 2023 at 14:2 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.