appsignal / mongo-rust-driver

Mongo Rust driver built on top of the Mongo C driver
Apache License 2.0
89 stars 22 forks source link

Fails to build on macOS #20

Closed jtomschroeder closed 7 years ago

jtomschroeder commented 7 years ago

Building the mongo_driver crate fails to link on macOS:

Undefined symbols for architecture x86_64:                                                                                             
"_SSLSetProtocolVersionMin", referenced from:                                                                                                  
    _mongoc_stream_tls_secure_transport_new in libmongoc_sys-4624d9f5191db692.rlib(libmongoc_1_0_la-mongoc-stream-tls-secure-transport.o)      
"_SSLSetSessionOption", referenced from:                                                                                                       
    _mongoc_stream_tls_secure_transport_new in libmongoc_sys-4624d9f5191db692.rlib(libmongoc_1_0_la-mongoc-stream-tls-secure-transport.o)      
"_SSLSetConnection", referenced from:                                                                                                          
    _mongoc_stream_tls_secure_transport_new in libmongoc_sys-4624d9f5191db692.rlib(libmongoc_1_0_la-mongoc-stream-tls-secure-transport.o)      
"_CFRelease", referenced from:                                                                                                                 
    __mongoc_secure_transport_RFC2253_from_cert in libmongoc_sys-4624d9f5191db692.rlib(libmongoc_1_0_la-mongoc-secure-transport.o)             
"_SSLHandshake", referenced from:                                                                                                              
    _mongoc_stream_tls_secure_transport_handshake in libmongoc_sys-4624d9f5191db692.rlib(libmongoc_1_0_la-mongoc-stream-tls-secure-transport.o)

...

Linking the Security and CoreFoundation frameworks appears to resolve the linking issues.

thijsc commented 7 years ago

Looks like this broke in Sierra, a fully clean compile does not work on my Mac anymore either.

The error on my machine is:

Undefined symbols for architecture x86_64:
  "_SSL_CTX_set1_param", referenced from:
      _mongoc_stream_tls_openssl_new in libmongoc-priv.a(libmongoc_priv_la-mongoc-stream-tls-openssl.o)
  "_X509_VERIFY_PARAM_set1_host", referenced from:
      _mongoc_stream_tls_openssl_new in libmongoc-priv.a(libmongoc_priv_la-mongoc-stream-tls-openssl.o)
  "_X509_VERIFY_PARAM_set1_ip_asc", referenced from:
      _mongoc_stream_tls_openssl_new in libmongoc-priv.a(libmongoc_priv_la-mongoc-stream-tls-openssl.o)
  "_X509_VERIFY_PARAM_set_hostflags", referenced from:
      _mongoc_stream_tls_openssl_new in libmongoc-priv.a(libmongoc_priv_la-mongoc-stream-tls-openssl.o)
ld: symbol(s) not found for architecture x86_64
thijsc commented 7 years ago

Upgrading the C driver in #21 did not fix it.

thijsc commented 7 years ago

These instructions fixed it for me:

brew install openssl
export LDFLAGS="-L/usr/local/opt/openssl/lib"
export CPPFLAGS="-I/usr/local/opt/openssl/include"
thijsc commented 7 years ago

I've added a note about this to the readme: 08ef8fbf2b94bb93d0f5e36e310a895d8539695c

Currently I don't see good options to make this smoother, so closing the issue.

ghost commented 5 years ago

@thijsc I've noticed that when pkg-config is installed on macOS, CPPFLAGS and LDFLAGS do not have effect, as the configure script tries to use pkg-config to detect OpenSSL and fails to do it because pkg-config package for OpenSSL is not configured by Homebrew. Once I've uninstalled pkg-config, the instructions with LDFLAGS and CPPFLAGS worked for me. It might be worth to mention this behavior in README.