ruipacheco
ruipacheco

Reputation: 16402

CMake returning mismatched includes and libraries for OpenSSL

I installed the latest version of OpenSSL (1.0.2q) via macports and I'm trying to build a project on my mac that depends on OpenSSL and found that CMake seems to be returning the wrong library path or the wrong include path:

message("@@@")
message(${OPENSSL_INCLUDE_DIR})
message(${OPENSSL_SSL_LIBRARY})
message("/@@@")

prints:

@@@
/opt/local/include
/usr/lib/libssl.dylib
/@@@

So it gives me headers for OpenSSL from macports and the library from system.

I found this because building an external library fails with linking errors:

Undefined symbols for architecture x86_64:
  "_X509_check_host", referenced from:
      _ma_tls_verify_server_cert in libmariadbclient.a(openssl.c.o)
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

How can I make CMake find and use macports libraries only?

Upvotes: 1

Views: 606

Answers (1)

Tsyvarev
Tsyvarev

Reputation: 65860

You may hint CMake about OpenSSL location with OPENSSL_ROOT_DIR environment variable (not CMake variable!) by setting it to /opt/local. Other ways of hints, described in CMake not able to find OpenSSL library could also work.


Note, that it could be quite tricky to "hide" the library under system directory /usr/lib from the linker and from the runtime loader. This is because other libraries, used by a project, can be located in that directory, and which may prevent CMake to build correct directories list for pass to the linker or for assign to RPATH. Normally, CMake warns about such situations.

Upvotes: 2

Related Questions