Friday, October 23, 2020

libngspice does not get built by default on macports

If you want to use PySpice, you first must have the library bindings installed. The Macports Portfile for ngspice does not build the libraries by default. Here's the symptom:
OSError: cannot load library 'libngspice.dylib': dlopen(libngspice.dylib, 2) : image not found. Additionally, ctypes.util.find_library() did not manage to locate a library called 'libngspice.dylib'
Basically, this means that there's just not a library. I couldn't find it anywhere, and then I realized that macports did not build the library by default.
Find where the portfile is:
sudo port file ngspice
Next, you have to edit it to add --with-ngshared:
    configure.args      --enable-cider \
                        --enable-xspice \
                        --enable-pss \
                        --with-editline \
                        --with-x \
                        --enable-debug=no \
                        --with-ngshared
Finally, you can build the port. If you have already installed it, you need to upgrade it:
sudo port -sn upgrade --force ngspice
I wish that there was some way to append a configuration argument via the command line, but I just cannot seem to make it work, even though there's a facility for it.

freehdl doesn't work as-is on macports

I had to add the following to the portfile:
configure.cxx_stdlib	libstdc++