• 5 min read
  • I have been testing the Drupal support module locally which features the ability to create tickets from email messages to an IMAP inbox. It requires the imap_open() PHP function provided by the imap PHP extension, which unfortunately is not included in the OS X builds of PHP.

    ivucica has published a wonderful script to his blog that compiles the IMAP extension without having to recompile PHP entirely, but unfortunately it was not working for me and nobody else seemed to have my problem either. Compiling the imap library and PCRE went very smoothly, but when it came time to build the PHP extension this error appeared during ./configure:

    checking whether build with IMAP works... no
    configure: error: build test failed. Please check the config.log for details.

    Well, crap. I check config.log and determine it's a linking failure:

    configure: program exited with status 1
    configure: failed program was:
    | /* confdefs.h */
    | #define PACKAGE_NAME ""
    | #define PACKAGE_TARNAME ""
    | #define PACKAGE_VERSION ""
    | #define PACKAGE_STRING ""
    | #define PACKAGE_BUGREPORT ""
    | #define PACKAGE_URL ""
    | #define COMPILE_DL_IMAP 1
    | #define HAVE_IMAP 1
    | #define HAVE_IMAP2000 1
    | #define HAVE_IMAP2004 1
    | #define HAVE_NEW_MIME2TEXT 1
    | #define HAVE_LIBPAM 1
    | #define HAVE_IMAP_KRB 1
    | #define HAVE_IMAP_SSL 1
    | /* end confdefs.h.  */
    |
    |
    | #if defined(__GNUC__) && __GNUC__ >= 4
    | # define PHP_IMAP_EXPORT __attribute__ ((visibility("default")))
    | #else
    | # define PHP_IMAP_EXPORT
    | #endif
    |
    |       PHP_IMAP_EXPORT void mm_log(void){}
    |       PHP_IMAP_EXPORT void mm_dlog(void){}
    |       PHP_IMAP_EXPORT void mm_flags(void){}
    |       PHP_IMAP_EXPORT void mm_fatal(void){}
    |       PHP_IMAP_EXPORT void mm_critical(void){}
    |       PHP_IMAP_EXPORT void mm_nocritical(void){}
    |       PHP_IMAP_EXPORT void mm_notify(void){}
    |       PHP_IMAP_EXPORT void mm_login(void){}
    |       PHP_IMAP_EXPORT void mm_diskerror(void){}
    |       PHP_IMAP_EXPORT void mm_status(void){}
    |       PHP_IMAP_EXPORT void mm_lsub(void){}
    |       PHP_IMAP_EXPORT void mm_list(void){}
    |       PHP_IMAP_EXPORT void mm_exists(void){}
    |       PHP_IMAP_EXPORT void mm_searched(void){}
    |       PHP_IMAP_EXPORT void mm_expunged(void){}
    |       void rfc822_output_address_list(void);
    |       void (*f)(void);
    |       char foobar () {f = rfc822_output_address_list;}
    |
    |     char foobar();
    |     int main() {
    |       foobar();
    |       return 0;
    |     }
    |
    configure:6808: result: no
    configure:6819: checking whether build with IMAP works
    configure:6863: cc -o conftest -g -O2   conftest.c  -Wl,-rpath,/usr/local/imap-2007f/lib -L/usr/local/imap-2007f/lib -lc-client -lpam  -lkrb5  >&5
    Undefined symbols for architecture x86_64:
      "_BIO_free", referenced from:
          _ssl_start in libc-client.a(osdep.o)
      "_BIO_new_mem_buf", referenced from:
          _ssl_start in libc-client.a(osdep.o)
      "_BIO_new_socket", referenced from:
          _ssl_start in libc-client.a(osdep.o)
      "_ERR_error_string", referenced from:
          _ssl_server_init in libc-client.a(osdep.o)
          _ssl_genkey in libc-client.a(osdep.o)
      "_ERR_get_error", referenced from:
          _ssl_server_init in libc-client.a(osdep.o)
          _ssl_genkey in libc-client.a(osdep.o)
      "_ERR_load_crypto_strings", referenced from:
          _ssl_server_init in libc-client.a(osdep.o)
      "_EVP_PKEY_free", referenced from:
          _ssl_start in libc-client.a(osdep.o)
      "_PEM_read_bio_PrivateKey", referenced from:
          _ssl_start in libc-client.a(osdep.o)
      "_PEM_read_bio_X509", referenced from:
          _ssl_start in libc-client.a(osdep.o)
      "_RAND_seed", referenced from:
          _ssl_onceonlyinit in libc-client.a(osdep.o)
      "_RSA_generate_key", referenced from:
          _ssl_genkey in libc-client.a(osdep.o)
      "_SSL_CTX_ctrl", referenced from:
          _ssl_server_init in libc-client.a(osdep.o)
          _ssl_start in libc-client.a(osdep.o)
      "_SSL_CTX_free", referenced from:
          _ssl_abort in libc-client.a(osdep.o)
      "_SSL_CTX_load_verify_locations", referenced from:
          _ssl_start in libc-client.a(osdep.o)
      "_SSL_CTX_new", referenced from:
          _ssl_server_init in libc-client.a(osdep.o)
          _ssl_start in libc-client.a(osdep.o)
      "_SSL_CTX_set_cipher_list", referenced from:
          _ssl_server_init in libc-client.a(osdep.o)
      "_SSL_CTX_set_default_verify_paths", referenced from:
          _ssl_start in libc-client.a(osdep.o)
      "_SSL_CTX_set_tmp_rsa_callback", referenced from:
          _ssl_server_init in libc-client.a(osdep.o)
      "_SSL_CTX_set_verify", referenced from:
          _ssl_start in libc-client.a(osdep.o)
      "_SSL_CTX_use_PrivateKey", referenced from:
          _ssl_start in libc-client.a(osdep.o)
      "_SSL_CTX_use_RSAPrivateKey_file", referenced from:
          _ssl_server_init in libc-client.a(osdep.o)
      "_SSL_CTX_use_certificate", referenced from:
          _ssl_start in libc-client.a(osdep.o)
      "_SSL_CTX_use_certificate_chain_file", referenced from:
          _ssl_server_init in libc-client.a(osdep.o)
      "_SSL_accept", referenced from:
          _ssl_server_init in libc-client.a(osdep.o)
      "_SSL_ctrl", referenced from:
          _ssl_start in libc-client.a(osdep.o)
      "_SSL_free", referenced from:
          _ssl_abort in libc-client.a(osdep.o)
      "_SSL_get_error", referenced from:
          _ssl_getdata in libc-client.a(osdep.o)
          _ssl_sout in libc-client.a(osdep.o)
      "_SSL_get_fd", referenced from:
          _ssl_getdata in libc-client.a(osdep.o)
          _ssl_server_input_wait in libc-client.a(osdep.o)
      "_SSL_get_peer_certificate", referenced from:
          _ssl_start in libc-client.a(osdep.o)
      "_SSL_library_init", referenced from:
          _ssl_onceonlyinit in libc-client.a(osdep.o)
      "_SSL_load_error_strings", referenced from:
          _ssl_server_init in libc-client.a(osdep.o)
      "_SSL_new", referenced from:
          _ssl_server_init in libc-client.a(osdep.o)
          _ssl_start in libc-client.a(osdep.o)
      "_SSL_pending", referenced from:
          _ssl_getdata in libc-client.a(osdep.o)
          _ssl_server_input_wait in libc-client.a(osdep.o)
      "_SSL_read", referenced from:
          _ssl_getdata in libc-client.a(osdep.o)
          _ssl_server_input_wait in libc-client.a(osdep.o)
      "_SSL_set_bio", referenced from:
          _ssl_start in libc-client.a(osdep.o)
      "_SSL_set_connect_state", referenced from:
          _ssl_start in libc-client.a(osdep.o)
      "_SSL_set_fd", referenced from:
          _ssl_server_init in libc-client.a(osdep.o)
      "_SSL_shutdown", referenced from:
          _ssl_abort in libc-client.a(osdep.o)
      "_SSL_state", referenced from:
          _ssl_start in libc-client.a(osdep.o)
      "_SSL_write", referenced from:
          _ssl_start in libc-client.a(osdep.o)
          _ssl_sout in libc-client.a(osdep.o)
      "_SSLv23_client_method", referenced from:
          _ssl_start in libc-client.a(osdep.o)
      "_SSLv23_server_method", referenced from:
          _ssl_server_init in libc-client.a(osdep.o)
      "_TLSv1_client_method", referenced from:
          _ssl_start in libc-client.a(osdep.o)
      "_TLSv1_server_method", referenced from:
          _ssl_server_init in libc-client.a(osdep.o)
      "_X509_NAME_oneline", referenced from:
          _ssl_open_verify in libc-client.a(osdep.o)
      "_X509_STORE_CTX_get_current_cert", referenced from:
          _ssl_open_verify in libc-client.a(osdep.o)
      "_X509_STORE_CTX_get_error", referenced from:
          _ssl_open_verify in libc-client.a(osdep.o)
      "_X509_free", referenced from:
          _ssl_start in libc-client.a(osdep.o)
      "_X509_get_ext_d2i", referenced from:
          _ssl_start in libc-client.a(osdep.o)
      "_X509_get_subject_name", referenced from:
          _ssl_open_verify in libc-client.a(osdep.o)
      "_X509_verify_cert_error_string", referenced from:
          _ssl_open_verify in libc-client.a(osdep.o)
      "_sk_num", referenced from:
          _ssl_start in libc-client.a(osdep.o)
      "_sk_value", referenced from:
          _ssl_start in libc-client.a(osdep.o)
    ld: symbol(s) not found for architecture x86_64
    clang: error: linker command failed with exit code 1 (use -v to see invocation)

    I couldn't figure out why it wasn't picking up the symbols from libssl, even when manually trying to compile said file and adding a -lssl flag.

    After an hour of struggling with it and my debugging efforts going nowhere, I try adding -lcrypto for the hell of it and it works!

    tl;dr, if you get this error then simply replace the following line of the aformentioned script:

    ./configure --with-imap=/usr/local/imap-2007f --with-kerberos --with-imap-ssl

    With the following line that adds the required linker flags:

    LDFLAGS="-lssl -lcrypto" ./configure --with-imap=/usr/local/imap-2007f --with-kerberos --with-imap-ssl

    That's it!