emscripten-core / emscripten-core/emscripten
Host CC cannot compile on Mac OS Monterey (12.2.1)
- Dominant language
- C++
- Stars
- 27.6k
- Forks
- 3.6k
- Avg merge
- 1d 1h
- Merged PRs (30d)
- 105
Description
With a fresh install of emsdk latest (I also tried tot), the bundled host compiler(clang, not emcc) cannot compile hello world.
I believe the the System framework has moved in Monterey somewhere under `/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/`, and this is not in the default search paths of the provided clang.
The error it gives is `ld: library not found for -lSystem`
This prevents me from building various third party projects using emconfigure (in this case GMP).
**Version of emscripten/emsdk:**
```
chris@ip-172-17-20-167 emsdk % emcc -v
emcc (Emscripten gcc/clang-like replacement + linker emulating GNU ld) 3.1.6-git (646de914928022fa83dff561c5b765e6e378c9a1)
clang version 15.0.0 (https://github.com/llvm/llvm-project 5acd9c49a85fb07d8cc04803c27e7aa1fb8c0211)
Target: wasm32-unknown-emscripten
Thread model: posix
InstalledDir: /Users/chris/dev/emsdk/upstream/bin
```
**The following is a terminal session reproducing the issue:**
```
chris@localhost dev % git clone https://github.com/emscripten-core/emsdk.git
chris@localhost dev % cd emsdk
chris@localhost emsdk % ./emsdk install tot
chris@localhost emsdk % ./emsdk activate tot
chris@localhost emsdk % source emsdk_env.sh
chris@localhost emsdk % emconfigure env | grep HOST_CC
configure: env
HOST_CC=/Users/chris/dev/emsdk/upstream/bin/clang
chris@localhost emsdk % cat - > main.c
int main() { return 0; }
chris@localhost emsdk % /Users/chris/dev/emsdk/upstream/bin/clang main.c
ld: library not found for -lSystem
clang-15: error: linker command failed with exit code 1 (use -v to see invocation)
chris@localhost emsdk % /Users/chris/dev/emsdk/upstream/bin/clang -v main.c
clang version 15.0.0 (https://github.com/llvm/llvm-project 5acd9c49a85fb07d8cc04803c27e7aa1fb8c0211)
Target: x86_64-apple-darwin21.3.0
Thread model: posix
InstalledDir: /Users/chris/dev/emsdk/upstream/bin
"/Users/chris/dev/emsdk/upstream/bin/clang-15" -cc1 -triple x86_64-apple-macosx12.0.0 -Wundef-prefix=TARGET_OS_ -Werror=undef-prefix -Wdeprecated-objc-isa-usage -Werror=deprecated-objc-isa-usage -emit-obj -mrelax-all --mrelax-relocations -disable-free -clear-ast-before-backend -main-file-name main.c -mrelocation-model pic -pic-level 2 -mframe-pointer=all -ffp-contract=on -fno-rounding-math -funwind-tables=2 -fcompatibility-qualified-id-block-type-checking -fvisibility-inlines-hidden-static-local-var -target-cpu penryn -tune-cpu generic -mllvm -treat-scalable-fixed-error-as-warning -debugger-tuning=lldb -target-linker-version 15.0.0 -v -fcoverage-compilation-dir=/Users/chris/dev/emsdk -resource-dir /Users/chris/dev/emsdk/upstream/lib/clang/15.0.0 -internal-isystem /usr/local/include -internal-isystem /Users/chris/dev/emsdk/upstream/lib/clang/15.0.0/include -internal-externc-isystem /usr/include -fdebug-compilation-dir=/Users/chris/dev/emsdk -ferror-limit 19 -stack-protector 1 -fblocks -fencode-extended-block-signature -fregister-global-dtors-with-atexit -fgnuc-version=4.2.1 -fmax-type-align=16 -fcolor-diagnostics -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /var/folders/pz/44zmfmfd26l657xjmcbfr0_00000gn/T/main-2254b8.o -x c main.c
clang -cc1 version 15.0.0 based upon LLVM 15.0.0git default target x86_64-apple-darwin21.3.0
ignoring nonexistent directory "/usr/local/include"
ignoring nonexistent directory "/usr/include"
#include "..." search starts here:
#include <...> search starts here:
/Users/chris/dev/emsdk/upstream/lib/clang/15.0.0/include
/System/Library/Frameworks (framework directory)
/Library/Frameworks (framework directory)
End of search list.
"/usr/bin/ld" -dynamic -arch x86_64 -macosx_version_min 12.0.0 -o a.out /var/folders/pz/44zmfmfd26l657xjmcbfr0_00000gn/T/main-2254b8.o -lSystem
ld: library not found for -lSystem
clang-15: error: linker command failed with exit code 1 (use -v to see invocation)
```
Providing an extra search path seems to fix the issue:
```
chris@localhost emsdk % LIBRARY_PATH="/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib" /Users/chris/dev/emsdk/upstream/bin/clang main.c
chris@localhost emsdk %
```
Contributor guide
Assessment
This issue has not been assessed yet.