The Crystal Programming Language Forum

Building compiler on Mac OS

Hello friends,

Excited to see 1.3 and crystal i. I’ve just given my first kick fo the can at compiling crystal and I almost got it! I can boot up crystal i just fine and do some basics. Sadly, the tests seem to fail and my actual project fails for the same reason. Something to do with SSL something or other…

speg@Steves-MacBook-Pro crystal % make std_spec compiler_spec
Using /usr/local/opt/llvm@11/bin/llvm-config [version= 11.1.0]
./bin/crystal build -D strict_multi_assign --link-flags="-L/usr/local/opt/openssl@3/lib" -Dwithout_interpreter  --exclude-warnings spec/std --exclude-warnings spec/compiler --exclude-warnings spec/primitives -o .build/std_spec spec/std_spec.cr
Using compiled compiler at .build/crystal
Undefined symbols for architecture x86_64:
  "_ERR_load_crypto_strings", referenced from:
      ___crystal_main in _main.o
  "_EVP_CIPHER_block_size", referenced from:
      _*OpenSSL::Cipher#block_size:Int32 in O-penS-S-L-5858C-ipher.o
  "_EVP_CIPHER_flags", referenced from:
      _*OpenSSL::Cipher#authenticated?:Bool in O-penS-S-L-5858C-ipher.o
  "_EVP_CIPHER_iv_length", referenced from:
      _*OpenSSL::Cipher#iv_len:Int32 in O-penS-S-L-5858C-ipher.o
  "_EVP_CIPHER_key_length", referenced from:
      _*OpenSSL::Cipher#key_len:Int32 in O-penS-S-L-5858C-ipher.o
  "_EVP_CIPHER_nid", referenced from:
      _*OpenSSL::Cipher#name:String in O-penS-S-L-5858C-ipher.o
  "_EVP_MD_CTX_create", referenced from:
      _*Digest::SHA512@OpenSSL::Digest#new_evp_mt_ctx<String>:Pointer(LibCrypto::EVP_MD_CTX_Struct) in D-igest5858S-H-A-512.o
      _*Digest::SHA512@OpenSSL::Digest#dup_ctx:Pointer(LibCrypto::EVP_MD_CTX_Struct) in D-igest5858S-H-A-512.o
      _*Digest::SHA256@OpenSSL::Digest#new_evp_mt_ctx<String>:Pointer(LibCrypto::EVP_MD_CTX_Struct) in D-igest5858S-H-A-256.o
      _*Digest::SHA256@OpenSSL::Digest#dup_ctx:Pointer(LibCrypto::EVP_MD_CTX_Struct) in D-igest5858S-H-A-256.o
      _*Digest::SHA1@OpenSSL::Digest#new_evp_mt_ctx<String>:Pointer(LibCrypto::EVP_MD_CTX_Struct) in D-igest5858S-H-A-1.o
      _*Digest::SHA1@OpenSSL::Digest#dup_ctx:Pointer(LibCrypto::EVP_MD_CTX_Struct) in D-igest5858S-H-A-1.o
      _*Digest::MD5@OpenSSL::Digest#new_evp_mt_ctx<String>:Pointer(LibCrypto::EVP_MD_CTX_Struct) in D-igest5858M-D-5.o
      ...
  "_EVP_MD_CTX_destroy", referenced from:
      _*OpenSSL::Digest+@OpenSSL::Digest#finalize:Nil in O-penS-S-L-5858D-igest43.o
      _*Digest::SHA512@OpenSSL::Digest#finalize:Nil in D-igest5858S-H-A-512.o
      _*Digest::SHA512@OpenSSL::Digest#dup_ctx:Pointer(LibCrypto::EVP_MD_CTX_Struct) in D-igest5858S-H-A-512.o
      _*Digest::SHA256@OpenSSL::Digest#finalize:Nil in D-igest5858S-H-A-256.o
      _*Digest::SHA256@OpenSSL::Digest#dup_ctx:Pointer(LibCrypto::EVP_MD_CTX_Struct) in D-igest5858S-H-A-256.o
      _*Digest::SHA1@OpenSSL::Digest#finalize:Nil in D-igest5858S-H-A-1.o
      _*Digest::SHA1@OpenSSL::Digest#dup_ctx:Pointer(LibCrypto::EVP_MD_CTX_Struct) in D-igest5858S-H-A-1.o
      ...
  "_EVP_MD_block_size", referenced from:
      _*OpenSSL::Digest#block_size:Int32 in O-penS-S-L-5858D-igest.o
  "_EVP_MD_size", referenced from:
      _*OpenSSL::Digest+@OpenSSL::Digest#digest_size:Int32 in O-penS-S-L-5858D-igest43.o
      _*Digest::SHA512@OpenSSL::Digest#digest_size:Int32 in D-igest5858S-H-A-512.o
      _*Digest::SHA256@OpenSSL::Digest#digest_size:Int32 in D-igest5858S-H-A-256.o
      _*Digest::SHA1@OpenSSL::Digest#digest_size:Int32 in D-igest5858S-H-A-1.o
      _*Digest::MD5@OpenSSL::Digest#digest_size:Int32 in D-igest5858M-D-5.o
      _*OpenSSL::Digest#digest_size:Int32 in O-penS-S-L-5858D-igest.o
  "_OPENSSL_add_all_algorithms_noconf", referenced from:
      ___crystal_main in _main.o
  "_SSL_get_peer_certificate", referenced from:
      _*OpenSSL::SSL::Socket::Server@OpenSSL::SSL::Socket#peer_certificate:(OpenSSL::X509::Certificate | Nil) in O-penS-S-L-5858S-S-L-5858S-ocket5858S-erver.o
      _*OpenSSL::SSL::Socket::Client@OpenSSL::SSL::Socket#peer_certificate:(OpenSSL::X509::Certificate | Nil) in O-penS-S-L-5858S-S-L-5858S-ocket5858C-lient.o
  "_SSL_library_init", referenced from:
      ___crystal_main in _main.o
  "_SSL_load_error_strings", referenced from:
      ___crystal_main in _main.o
  "_SSLv23_method", referenced from:
      _*OpenSSL::SSL::Context::default_method:Pointer(Void) in O-penS-S-L-5858S-S-L-5858C-ontext.o
  "_sk_free", referenced from:
      _~procProc(Pointer(Void), Nil)@src/openssl/ssl/hostname_validation.cr:71 in _main.o
      _~proc2Proc(Pointer(Void), Nil)@src/openssl/ssl/hostname_validation.cr:71 in _main.o
      _~proc3Proc(Pointer(Void), Nil)@src/openssl/ssl/hostname_validation.cr:71 in _main.o
      _~proc4Proc(Pointer(Void), Nil)@src/openssl/ssl/hostname_validation.cr:71 in _main.o
      _~proc5Proc(Pointer(Void), Nil)@src/openssl/ssl/hostname_validation.cr:71 in _main.o
      _~proc6Proc(Pointer(Void), Nil)@src/openssl/ssl/hostname_validation.cr:71 in _main.o
  "_sk_num", referenced from:
      _*OpenSSL::SSL::HostnameValidation::matches_subject_alternative_name<String, Pointer(Void)>:OpenSSL::SSL::HostnameValidation::Result in O-penS-S-L-5858S-S-L-5858H-ostnameV-alidation.o
  "_sk_pop_free", referenced from:
      _*OpenSSL::SSL::HostnameValidation::matches_subject_alternative_name<String, Pointer(Void)>:OpenSSL::SSL::HostnameValidation::Result in O-penS-S-L-5858S-S-L-5858H-ostnameV-alidation.o
  "_sk_value", referenced from:
      _*OpenSSL::SSL::HostnameValidation::matches_subject_alternative_name<String, Pointer(Void)>:OpenSSL::SSL::HostnameValidation::Result in O-penS-S-L-5858S-S-L-5858H-ostnameV-alidation.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Error: execution of command failed with code: 1: `cc "${@}" -o /Users/speg/Crystal/crystal/.build/std_spec -L/usr/local/opt/openssl@3/lib -rdynamic -L/usr/local/lib /Users/speg/Crystal/crystal/src/llvm/ext/llvm_ext.o `"/usr/local/opt/llvm@11/bin/llvm-config" --libs --system-libs --ldflags 2> /dev/null` -lstdc++ `command -v pkg-config > /dev/null && pkg-config --libs --silence-errors libssl || printf %s '-lssl -lcrypto'` `command -v pkg-config > /dev/null && pkg-config --libs --silence-errors libcrypto || printf %s '-lcrypto'` -lxml2 -lz -L/usr/local/Cellar/libyaml/0.2.5/lib -lyaml -L/usr/local/Cellar/gmp/6.2.1_1/lib -lgmp -lpcre -lgc -lpthread -L/usr/local/Cellar/libevent/2.1.12/lib -levent -liconv -ldl`

Sadly, this is a bit over my head at the moment. Does it make any sense to any of you?
I assume it has something to do with openssl…

% openssl version
OpenSSL 3.0.1 14 Dec 2021 (Library: OpenSSL 3.0.1 14 Dec 2021)

If you happen to be using a M1 Mac, try running which openssl. If that doesn’t return /usr/bin/openssl, then try running brew unlink openssl and give the Crystal build a shot again. If which openssl does return /usr/bin/openssl… then I’m not sure :sweat_smile:

Openssl and M1 has sort of been a big issue around the Lucky discord lately. If you feel like dropping in Lucky there’s a few people that have had some luck getting around this.