Linking with OpenSSL

I struggled to link with OpenSSL library. I thought this is a good opportunity to learn more about cmake. However, I couldn’t find a solution. I tried find_package. Not working. Then tried manual setting of include dir and library files – still not working, ld says it cannot find -lssl.

I then tried making Makefile manually – it just worked. But there’s a ld’s warnings:

ld: warning: dylib (/opt/homebrew/opt/openssl/lib/libcrypto.dylib) was built for newer macOS version (12.0) than being linked (11.3)

ld: warning: dylib (/opt/homebrew/opt/openssl/lib/libssl.dylib) was built for newer macOS version (12.0) than being linked (11.3)

Forget about the warning for now. I then tried different library such as libjpeg with cmake. Still doesn’t work. I then tried a library which resides in the standard library path such as /usr/lib. Worked. So, my problem is purely link_directories command not working at all. Then finally I found this. I had been thinking the problem was specific to OpenSSL because it is very complicated but it turned out it was just a wrong usage of cmake.

Lesson learned – when you are working on a new tool, always try from the basic things.

Leave a Reply

Your email address will not be published. Required fields are marked *