【问题标题】:Error: OpenSSL on Apple Silicon: libcrypto.dylib, building for macOS-arm64 but attempting to link with file built for macOS-x86_64错误:Apple Silicon 上的 OpenSSL:libcrypto.dylib,为 macOS-arm64 构建,但尝试链接为 macOS-x86_64 构建的文件
【发布时间】:2021-08-17 05:01:52
【问题描述】:

我正在编写一个使用 OpenSSL 的程序。它工作正常,然后我重置/删除了 CMake 缓存。我现在收到以下错误消息。

我使用 Homebrew 安装了 OpenSSL。我在我的 .bash_profile 中添加了以下内容:

导出 PKG_CONFIG_PATH="/opt/homebrew/opt/openssl@1.1/lib/pkgconfig"

我将此添加到 /etc/paths 的全局路径文件中:

/opt/homebrew/opt/openssl@1.1/bin

还有哪些其他修复/建议可用于调试此问题?

错误:

/Applications/CLion.app/Contents/bin/cmake/mac/bin/cmake --build /Users/stephenjje/Documents/Je/test/cmake-build-debug --target test -- -j 6
[  2%] Linking C executable test
ld: warning: ignoring file /usr/local/Cellar/openssl@1.1/1.1.1k/lib/libcrypto.dylib, building for macOS-arm64 but attempting to link with file built for macOS-x86_64
ld: warning: ignoring file /usr/local/Cellar/openssl@1.1/1.1.1k/lib/libssl.dylib, building for macOS-arm64 but attempting to link with file built for macOS-x86_64
Undefined symbols for architecture arm64:
  "_ERR_print_errors_fp", referenced from:
      _http_tcpip_inbound_initialize in http_tcpip_inbound.c.o
      _http_tcpip_inbound_tls_initialize in http_tcpip_inbound.c.o
      _http_tcpip_outbound_get_url_using_string_type_tls in http_tcpip_outbound.c.o
  "_OPENSSL_init_crypto", referenced from:
      _http_tcpip_inbound_tls_initialize in http_tcpip_inbound.c.o
  "_OPENSSL_init_ssl", referenced from:
      _http_tcpip_inbound_tls_initialize in http_tcpip_inbound.c.o
  "_SSL_CIPHER_get_name", referenced from:
      _http_tcpip_inbound_initialize in http_tcpip_inbound.c.o
  "_SSL_CTX_free", referenced from:
      _http_tcpip_inbound_initialize in http_tcpip_inbound.c.o
  "_SSL_CTX_new", referenced from:
      _http_tcpip_inbound_tls_initialize in http_tcpip_inbound.c.o
      _http_tcpip_outbound_get_url_using_string_type_tls in http_tcpip_outbound.c.o
  "_SSL_CTX_use_PrivateKey_file", referenced from:
      _http_tcpip_inbound_tls_initialize in http_tcpip_inbound.c.o
  "_SSL_CTX_use_certificate_file", referenced from:
      _http_tcpip_inbound_tls_initialize in http_tcpip_inbound.c.o
  "_SSL_accept", referenced from:
      _http_tcpip_inbound_initialize in http_tcpip_inbound.c.o
  "_SSL_connect", referenced from:
      _http_tcpip_outbound_get_url_using_string_type_tls in http_tcpip_outbound.c.o
  "_SSL_ctrl", referenced from:
      _http_tcpip_outbound_get_url_using_string_type_tls in http_tcpip_outbound.c.o
  "_SSL_free", referenced from:
      _http_tcpip_inbound_initialize in http_tcpip_inbound.c.o
  "_SSL_get_current_cipher", referenced from:
      _http_tcpip_inbound_initialize in http_tcpip_inbound.c.o
  "_SSL_get_peer_certificate", referenced from:
      _http_tcpip_outbound_get_url_using_string_type_tls in http_tcpip_outbound.c.o
  "_SSL_new", referenced from:
      _http_tcpip_inbound_initialize in http_tcpip_inbound.c.o
      _http_tcpip_outbound_get_url_using_string_type_tls in http_tcpip_outbound.c.o
  "_SSL_read", referenced from:
      _http_tcpip_inbound_parse_request in http_tcpip_inbound.c.o
      _http_tcpip_outbound_get_url_using_string_type_tls in http_tcpip_outbound.c.o
  "_SSL_set_fd", referenced from:
      _http_tcpip_inbound_initialize in http_tcpip_inbound.c.o
      _http_tcpip_outbound_get_url_using_string_type_tls in http_tcpip_outbound.c.o
  "_SSL_shutdown", referenced from:
      _http_tcpip_inbound_initialize in http_tcpip_inbound.c.o
  "_SSL_write", referenced from:
      _http_tcpip_inbound_send_response in http_tcpip_inbound.c.o
      _http_tcpip_outbound_request_send_type_tls in http_tcpip_outbound.c.o
  "_TLS_client_method", referenced from:
      _http_tcpip_outbound_get_url_using_string_type_tls in http_tcpip_outbound.c.o
  "_TLS_server_method", referenced from:
      _http_tcpip_inbound_tls_initialize in http_tcpip_inbound.c.o
  "_X509_free", referenced from:
      _http_tcpip_outbound_get_url_using_string_type_tls in http_tcpip_outbound.c.o
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
gmake[3]: *** [CMakeFiles/test.dir/build.make:680: test] Error 1
gmake[2]: *** [CMakeFiles/Makefile2:83: CMakeFiles/test.dir/all] Error 2
gmake[1]: *** [CMakeFiles/Makefile2:90: CMakeFiles/test.dir/rule] Error 2

【问题讨论】:

    标签: c openssl homebrew clion pkg-config


    【解决方案1】:

    您使用的是 M1 Mac 吗?从错误输出中,您在/usr/local 下安装了 Homebrew,这表明您使用的是 x86 Mac。但是/opt/homebrew是M1 Mac的安装位置。

    我猜你只是在使用 x86 Mac,但是你从网络上的某个地方复制了这个 /opt/homebrew/opt/openssl@1.1 东西。您的 CLion 尝试为 arm64 设备构建。当然它失败了,因为你根本不在手臂机器上。更改您的构建设置并停止为arm 构建您的项目,但仅限于x86 设备。

    我不知道如何在 CLion 中执行此操作,但在 XCode 中有一些示例。 Xcode 12, building for iOS Simulator, but linking in object file built for iOS, for architecture arm64

    【讨论】:

    • 嗨。我正在使用 M1。
    • 我调查并安装了两个 Homebrew:一个用于 Intel,另一个用于 M1。两者都安装了 OpenSSL。如何检查 OpenSSL 安装是否指向正确的位置(并且与 M1 兼容)?
    • @PeteMitchell 我明白了。起初,M1 Mac 中没有原生 ARM 自制软件支持。 Homebrew 是用 Rosetta2 实现的(支持在 arm 机器上运行 x86 构建)。这就是您机器上的/usr/local/ 安装的来源。现在,您应该从 Rosetta2 homebrew 迁移到本机 ARM homebrew 并卸载旧的 Rosetta2 brew。 homebrew discussion 有一些指南。
    猜你喜欢
    • 2021-04-24
    • 2022-01-04
    • 2022-06-23
    • 2022-08-24
    • 2022-01-19
    • 2021-09-24
    • 1970-01-01
    • 2021-12-29
    • 2023-03-09
    相关资源
    最近更新 更多