1

I'm writing a program that uses OpenSSL. It was working correctly, then I reset/removed the CMake cache. I now get the error messages below.

I installed OpenSSL using Homebrew. I added the following to my .bash_profile:

export PKG_CONFIG_PATH="/opt/homebrew/opt/openssl@1.1/lib/pkgconfig"

I added this to the global path file at /etc/paths:

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

What are some other fixes/suggestions for debugging this issue?

Errors:

/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
Pete Mitchell
  • 53
  • 1
  • 2
  • 7

1 Answers1

5

Are you using a M1 Mac? From the error output, you have Homebrew installed under /usr/local, which indicates you're using a x86 Mac. But /opt/homebrew is the installation location for M1 Mac.

My guess you're just using a x86 Mac, but you copied this /opt/homebrew/opt/openssl@1.1 thing from somewhere on the web. Your CLion tries to build for arm64 devices. Of course it fails cause you're NOT on an arm machine at all. Change your build settings and stop building your project for arm but only for x86 devices.

I don't know how to do this in CLion but there're exmaples do is in XCode. Xcode 12, building for iOS Simulator, but linking in object file built for iOS, for architecture arm64

Simba
  • 23,537
  • 7
  • 64
  • 76
  • Hi. I'm using an M1. – Pete Mitchell Aug 19 '21 at 05:01
  • I investigated and have two Homebrew installations: one for Intel and the other M1. OpenSSL is installed on both. How can I check that the OpenSSL installation is pointing to the right place (and is M1-compatible)? – Pete Mitchell Aug 19 '21 at 05:37
  • 1
    @PeteMitchell I got it. At first there's no native ARM homebrew support in M1 Mac. Homebrew was implemented with Rosetta2 (support running x86 build on arm machine). This is where the `/usr/local/` installation on your machine comes from. Nowadays, you should migrate from Rosetta2 homebrew to native ARM homebrew and uninstall the old Rosetta2 brew. There's some guide in [homebrew discussion](https://github.com/Homebrew/discussions/discussions/707#discussioncomment-342325). – Simba Aug 19 '21 at 07:25