苹果硅胶M1上的水晶郎

Дер*_*гей 5 linker openssl crystal-lang apple-m1

当我尝试通过此驱动程序连接到 DB(Postgres) 时https://github.com/will/crystal-pg

require "pg"
cnn = PG.connect("postgres://root:password@localhost/my_db_dev")
Run Code Online (Sandbox Code Playgroud)

我在编译过程中遇到错误

Undefined symbols for architecture arm64:
  "_EVP_MD_size", referenced from:
      _*OpenSSL::Digest#digest_size:Int32 in O-penS-S-L-5858D-igest.o
      _*Digest::MD5@OpenSSL::Digest#digest_size:Int32 in D-igest5858M-D-5.o
ld: symbol(s) not found for architecture arm64
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/serg/Pro/demka/demka  -rdynamic -L/opt/homebrew/lib -lz `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'` -lpcre -lgc -lpthread -L/opt/homebrew/Cellar/libevent/2.1.12/lib -levent -liconv -ldl`
Run Code Online (Sandbox Code Playgroud)

crystal -v

Crystal 1.2.1 (2021-10-21)

LLVM: 11.1.0
Default target: aarch64-apple-darwin21.1.0
Run Code Online (Sandbox Code Playgroud)

LLVM 10.0 也会发生同样的错误。macbook m1上可以用crystal开发吗?在我之前使用 ubuntu 的笔记本电脑上,我没有遇到这样的错误。

另外,我尝试从来源制作水晶并得到同样的错误

Using /opt/homebrew/opt/llvm@11/bin/llvm-config [version=11.1.0]
CRYSTAL_CONFIG_BUILD_COMMIT="5c6685cc7" CRYSTAL_CONFIG_PATH='$ORIGIN/../share/crystal/src' SOURCE_DATE_EPOCH="1636378125" CRYSTAL_CONFIG_LIBRARY_PATH='$ORIGIN/../lib/crystal' ./bin/crystal build  -o .build/crystal src/compiler/crystal.cr -D without_openssl -D without_zlib
Undefined symbols for architecture arm64:
  "_iconv", referenced from:
      _*IO::Decoder#read<IO::FileDescriptor+>:Nil in _main.o
      _*IO::FileDescriptor@IO#write_string<Slice(UInt8)>:Nil in _main.o
  "_iconv_close", referenced from:
      _~proc3Proc(Pointer(Void), Pointer(Void), Nil)@src/gc/boehm.cr:172 in _main.o
      _~proc5Proc(Pointer(Void), Pointer(Void), Nil)@src/gc/boehm.cr:172 in _main.o
  "_iconv_open", referenced from:
      _*Crystal::Iconv::new<String, String, (Symbol | Nil)>:Crystal::Iconv in _main.o
ld: symbol(s) not found for architecture arm64
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/serg/.cache/crystal/Users-serg-Apps-crystal-src-ecr-process.cr/macro_run  -rdynamic -L/Users/serg/Downloads/crystal-1.2.1-1/embedded/lib -L/Users/serg/Downloads/crystal-1.2.1-1/embedded/lib -lpcre -lgc -lpthread -L/opt/local/lib -levent -liconv -ldl`
make: *** [.build/crystal] Error 1
Run Code Online (Sandbox Code Playgroud)

我尝试用罗塞塔制作它,有同样的错误

Using /opt/homebrew/opt/llvm@11/bin/llvm-config [version=11.1.0]
CRYSTAL_CONFIG_BUILD_COMMIT="5c6685cc7" CRYSTAL_CONFIG_PATH='$ORIGIN/../share/crystal/src' SOURCE_DATE_EPOCH="1636378125" CRYSTAL_CONFIG_LIBRARY_PATH='$ORIGIN/../lib/crystal' ./bin/crystal build  -o .build/crystal src/compiler/crystal.cr -D without_openssl -D without_zlib
ld: warning: ignoring file /opt/local/lib/libiconv.dylib, building for macOS-x86_64 but attempting to link with file built for macOS-arm64
Undefined symbols for architecture x86_64:
  "_iconv", referenced from:
      _*IO::Decoder#read<IO::FileDescriptor+>:Nil in _main.o
      _*IO::FileDescriptor@IO#write_string<Slice(UInt8)>:Nil in _main.o
  "_iconv_close", referenced from:
      _~proc3Proc(Pointer(Void), Pointer(Void), Nil)@src/gc/boehm.cr:172 in _main.o
      _~proc5Proc(Pointer(Void), Pointer(Void), Nil)@src/gc/boehm.cr:172 in _main.o
  "_iconv_open", referenced from:
      _*Crystal::Iconv::new<String, String, (Symbol | Nil)>:Crystal::Iconv in _main.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/serg/.cache/crystal/Users-serg-Apps-crystal-src-ecr-process.cr/macro_run  -rdynamic -L/Users/serg/Downloads/crystal-1.2.1-1/embedded/lib -L/Users/serg/Downloads/crystal-1.2.1-1/embedded/lib -lpcre -lgc -lpthread -L/opt/local/lib -levent -liconv -ldl`
make: *** [.build/crystal] Error 1
Run Code Online (Sandbox Code Playgroud)

我不想从源头上制造晶体,我认为这可以解决我的问题,我只是想得到一个可以工作的晶体。

所以,现在我有了来自brew安装的水晶

Crystal 1.2.1 (2021-10-21)
LLVM: 11.1.0
Default target: aarch64-apple-darwin21.1.0
Run Code Online (Sandbox Code Playgroud)

而且,我在编译过程中仍然遇到错误

Undefined symbols for architecture arm64:
  "_EVP_MD_size", referenced from:
      _*OpenSSL::Digest#digest_size:Int32 in O-penS-S-L-5858D-igest.o
      _*Digest::MD5@OpenSSL::Digest#digest_size:Int32 in D-igest5858M-D-5.o
  "_iconv", referenced from:
      _*Crystal::Iconv#convert<Pointer(Pointer(UInt8)), Pointer(UInt64), Pointer(Pointer(UInt8)), Pointer(UInt64)>:UInt64 in C-rystal5858I-conv.o
  "_iconv_close", referenced from:
      _*Crystal::Iconv#close:Nil in C-rystal5858I-conv.o
  "_iconv_open", referenced from:
      _*Crystal::Iconv#initialize<String, String, (Symbol | Nil)>:Nil in C-rystal5858I-conv.o
ld: symbol(s) not found for architecture arm64
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/serg/.cache/crystal/crystal-run-demka.tmp  -rdynamic -L/opt/homebrew/lib -lz `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'` -lpcre -lgc -lpthread -L/opt/local/lib -levent -liconv -ldl`

Run Code Online (Sandbox Code Playgroud)

所有接下来的环境都是空的

$CRYSTAL_LIBRARY_PATH  #empty
$LIBRARY_PATH          #empty
$PKG_CONFIG_PATH       #empty
Run Code Online (Sandbox Code Playgroud)

但命令crystal env

CRYSTAL_CACHE_DIR=/Users/serg/.cache/crystal
CRYSTAL_PATH=lib:/opt/homebrew/Cellar/crystal/1.2.1/libexec/../share/crystal/src:/opt/homebrew/Cellar/crystal/1.2.1/src
CRYSTAL_VERSION=1.2.1
CRYSTAL_LIBRARY_PATH=/opt/homebrew/lib
CRYSTAL_OPTS=''
Run Code Online (Sandbox Code Playgroud)

如何修复 OpenSSL 链接?

Jon*_*Haß 2

确保您拥有 Homebrew 的最新 crystal 软件包以及 openssl@1.1 软件包:

brew upgrade
brew install crystal openssl@1.1
Run Code Online (Sandbox Code Playgroud)

确保 Homebrew 软件包的包装器位于您的路径中:

$ which crystal
/opt/homebrew/bin/crystal
Run Code Online (Sandbox Code Playgroud)

您没有设置显式的PKG_CONFIG_PATH并且包装器正确设置了它:

$ echo $PKG_CONFIG_PATH

$ grep PKG $(which crystal)
export PKG_CONFIG_PATH="${PKG_CONFIG_PATH:+$PKG_CONFIG_PATH:}/opt/homebrew/opt/openssl@1.1/lib/pkgconfig
Run Code Online (Sandbox Code Playgroud)

要从源代码构建 Crystal,您需要安装所有依赖项。从错误消息来看,似乎 libiconv 丢失或无法找到。