Installing Easysnmp With Homebrew

Navigating the narrow passage of OpenSSL and Net-SNMP on MacOS to install a Python module in the virtualenv
September 14, 2018
homebrew macos openssl net-snmp

You might be familiar with the horrors of the default OpenSSL installation on MacOS. The suggested solution for this is to upgrade/install OpenSSL via Homebrew. While this works, it introduces subtle new problems that ripple outward and appear like sea monsters when least expected.

I recently upgraded my MBP to the 2018 model. While rebuilding a virtualenv for one of my projects, easysnmp refused to build:

ld: library not found for -lcrypto.35
clang: error: linker command failed with exit code 1 (use -v to see invocation)
error: command 'clang' failed with exit status 1

Hmm. Digging around showed me first that when activating the virtualenv, my shell (Fish) was not keeping the alternate path locations. I want to use the OpenSSL libraries in /usr/local/opt/openssl/bin, but which openssl was continuing to show me /usr/bin/openssl. Further poking showed that this is actually happening in the embedded terminal in VS Code, not in iTerm. So, over to iTerm we go.

To review the changes, in order to force the Homebrew OpenSSL installation to come first, I have the following in ~/.config/fish/config.fish:

set -g -x fish_user_paths "/usr/local/opt/openssl/bin" "/usr/local/sbin" "/usr/local/bin" $fish_user_paths

I nuked the virtualenv and started over. Same problem. The library linked with lcrypto.35 is in /usr/lib.

Further digging led me to net-snmp-config, which is responsible for telling the linker what libraries SNMP is linked against. Sure enough, fish is finding this in /usr/bin.

Next step: brew install net-snmp and update fish_user_paths to include /usr/local/opt/net-snmp/bin and /usr/local/opt/net-snmp/sbin. Deactivate and reactivate the venv, and voila! We’re in business…or are we?

Easysnmp builds, but when I run my app, it immediately bails with SIGABRT as it tries to call netsnmp_create_session. This means that although Easysnmp built correctly, it linked against the wrong libraries.

Back to the Fish config! I added this:

set -gx LDFLAGS "-L/usr/local/opt/net-snmp/lib"
set -gx CPPFLAGS "-I/usr/local/opt/net-snmp/include"

After re-sourcing the config file, I rebuilt Easysnmp in the virtualenv, and now, it works. For real. For really real.

Frustrating.