Llvm_config on macos (newbie in trouble)

Could somebody help me build crystal for macOS?

627 rmills@rmillsm1:~/gnu/github/crystal/crystal $ make
Error: Could not find location of llvm-config. Please specify path in environment variable LLVM_CONFIG.
Supported LLVM versions: 14 13 12 11.1 11 10 9 8
Makefile:203: *** Could not locate compatible llvm-config, make sure it is installed and in your PATH, or set LLVM_CONFIG. Compatible versions: 14.0 13.0 12.0 11.1 11.0 10.0 9.0 8.0. Stop.

628 rmills@rmillsm1:~/gnu/github/crystal/crystal $ sw_vers
ProductName: macOS
ProductVersion: 13.1
BuildVersion: 22C65

629 rmills@rmillsm1:~/gnu/github/crystall/crystal $ cc --version
Apple clang version 14.0.0 (clang-1400.0.29.202)
Target: arm64-apple-darwin22.2.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin
630 rmills@rmillsm1:~/gnu/github/crystal/crystal $

I’ve installed the “pre-built” crystal

632 rmills@rmillsm1:~/gnu/github/crystal/crystal $ crystal --version
Crystal 1.7.2 [29f9ac503] (2023-01-23)

LLVM: 10.0.0
Default target: aarch64-apple-darwin
633 rmills@rmillsm1:~/gnu/github/crystal/crystal $ crystal env      
634 rmills@rmillsm1:~/gnu/github/crystall/crystal $ 

It’s brittle (crashes easily), especially when engaging with crypto and SSL. So I can get neither the HTTPserver tutorial nor crystall play to work:

637 rmills@rmillsm1:~/gnu/github/crystal/crystal $ crystal play
Listening on
Undefined symbols for architecture arm64:
  "_ERR_load_crypto_strings", referenced from:
      ___crystal_main in _main.o
  "_OPENSSL_add_all_algorithms_noconf", referenced from:
      ___crystal_main in _main.o

Should I work on my Intel machine? Should I work on Linux? I would appreciate a little assistance to get rolling with crystal.

I’ve downloaded LLVM from GitHub, built and installed.

535 rmills@rmillsm1:~/gnu/github/crystal/crystal $ which llvm-config
536 rmills@rmillsm1:~/gnu/github/crystal/crystal $ export LLVM_CONFIG=/usr/local/bin/llvm-config 
537 rmills@rmillsm1:~/gnu/github/crystal/crystal $ llvm-config --cxxflags
-I/usr/local/include -std=c++17   -fno-exceptions -fno-rtti -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS
538 rmills@rmillsm1:~/gnu/github/crystal/crystal $ llvm-config --version 
539 rmills@rmillsm1:~/gnu/github/crystal/crystal $ 

Build crystal:

528 rmills@rmillsm1:~/gnu/github/crystal/crystal $ make
Using /usr/local/bin/llvm-config [version= 17.0.0git]
c++ -c  -o src/llvm/ext/llvm_ext.o src/llvm/ext/llvm_ext.cc -I/usr/local/include -std=c++17   -fno-exceptions -fno-rtti -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS
src/llvm/ext/llvm_ext.cc:11:10: fatal error: 'llvm/ADT/Triple.h' file not found
#include <llvm/ADT/Triple.h>
1 error generated.
make: *** [src/llvm/ext/llvm_ext.o] Error 1

Triple.h is in TargetParser:

529 rmills@rmillsm1:~/gnu/github/crystal/crystal $ find /usr -name Triple.h
530 rmills@rmillsm1:~/gnu/github/crystal/crystal $ 

Maybe llvm17.0.0git has moved Triple.h. I’ll try 14.0.6 (and, if necessary, 10.0)

Nope. Different bed of nails. I give up.

63 rmills@rmillsm1:~/gnu/github/crystal/crystal $ make clean
rm -rf .build
rm -rf ./docs
rm -rf src/llvm/ext/llvm_ext.o
564 rmills@rmillsm1:~/gnu/github/crystal/crystal $ make
Using /usr/local/bin/llvm-config [version= 14.0.6]
c++ -c  -o src/llvm/ext/llvm_ext.o src/llvm/ext/llvm_ext.cc -I/usr/local/include -std=c++14   -fno-exceptions -fno-rtti -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS
In file included from src/llvm/ext/llvm_ext.cc:1:
In file included from /usr/local/include/llvm/IR/DIBuilder.h:17:
In file included from /usr/local/include/llvm/ADT/ArrayRef.h:12:
In file included from /usr/local/include/llvm/ADT/Hashing.h:49:
In file included from /usr/local/include/llvm/Support/SwapByteOrder.h:17:
/usr/local/include/llvm/ADT/bit.h:64:56: error: no template named 'is_integral_v' in namespace 'std'; did you mean 'is_integral'?
template <typename T, typename = std::enable_if_t<std::is_integral_v<T>>>

I tried one more time. I built llvm 14.0.6 from the source to be sure everything was built for Apple Silicon (arm64). The build ate my 50gbytes of free space on the disc (filling it with static libraries).

src/llvm/ext/llvm_ext.cc compiled and refused to link due to an arm64/x86_64 link issue.

I’ve remembered why I have retired. Best Wishes to Crystal. I’m going to keep my focus on the euphonium.

Try llvm@14 from homebrew because llvm 15 isn’t supported yet.

Why are you trying to build the compiler? I mean there’s obviously nothing wrong with that, and it shouldn’t be hard to to if you want to.
But if I read your first comment correctly, you’re actually trying to do something else, compiling a Crystal program such as the HTTP server tutorial, and that fails. So I assume you’re trying to build the compiler in search for solving this problem?
That’s probably not going to help.

If you want to address this problem, it should be sufficient to fix the OpenSSL linker issue.
I’m not using MacOS and can’t tell you exactly what’s going on, but I know there have been problems with linking the system-provided OpenSSL library.
The solution is installing a good libssl manually. You can find some help on that in the installation instructions: Install On macOS - The Crystal Programming Language The reported error message there is different, but it could be the same problem. You don’t need to install OpenSSL via brew (that’s just what apparently most people use on macOS), the important part is to make it available in pkgconfig before the SSL library provided by the OS.

That sounds aweful. I know LLVM can eat quite a bit, but that seems to be way too much. Maybe you’re building more than you need…?

Please don’t let me disturb your music :trumpet:
Just offering help in case you want to try it again.

Ah, thank you, @straight-shoota and @asterite. Crystal looks wonderful. I appreciate your help. The crystal binary for darwin-arm64 installs and works well. I’m very interested in the language because I’ve implemented interpreters, compilers and debuggers.

Building llvm/Crystal on macOS is off-topic. Apologies for the noise from the Euphonium.

(I’ll be back and assure you of my best wishes).


I’ve cleaned up this mess, and everything’s working now, including ‘crystal play’.

In particular, I:

  1. Removed /usr/local/{bin|include|lib}
  2. Ran $ brew doctor.
    He told me to delete something concerning ‘core’
    Then he downloaded something big from git
  3. brew install {openssl|curl|crystal}

Happiness and I don’t need to build crystal.

I will now learn some crystal charms. Thank you @straight-shoota and @asterite for your support and encouragement. As a reward for your help, I promise not to play you a tune on the Euphonium!