How to avoid conflicting ngspice versions

Because the default version of KiCad was rather old, I installed KICAD5.1 from the ppa of js-reynaud on my Linux Mint 19.2 system, this is what the version info shows:
Application: KiCad
Version: 5.1.4-e60b266~84~ubuntu18.04.1, release build
Libraries:
wxWidgets 3.0.4
libcurl/7.58.0 OpenSSL/1.1.1 zlib/1.2.11 libidn2/2.0.4 libpsl/0.19.1 (+libidn2/2.0.4) nghttp2/1.30.0 librtmp/2.3
Platform: Linux 4.15.0-58-generic x86_64, 64 bit, Little endian, wxGTK
Build Info:
wxWidgets: 3.0.4 (wchar_t,wx containers,compatible with 2.8) GTK+ 3.22
Boost: 1.65.1
OpenCASCADE Community Edition: 6.9.1
Curl: 7.58.0
Compiler: GCC 7.4.0 with C++ ABI 1011

Build settings:
USE_WX_GRAPHICS_CONTEXT=OFF
USE_WX_OVERLAY=ON
KICAD_SCRIPTING=ON
KICAD_SCRIPTING_MODULES=ON
KICAD_SCRIPTING_PYTHON3=ON
KICAD_SCRIPTING_WXPYTHON=ON
KICAD_SCRIPTING_WXPYTHON_PHOENIX=ON
KICAD_SCRIPTING_ACTION_MENU=ON
BUILD_GITHUB_PLUGIN=ON
KICAD_USE_OCE=ON
KICAD_USE_OCC=OFF
KICAD_SPICE=ON

This KiCad5.1.4 version uses ngspice-30 and it worked rather fine. However, because I often prefer not to draw schematics, I also wanted to run ngspice from the command line. Unfortunately the ngspice-version which is by default installed on the same system was ngspice-27 which is also rather old. Therefore I purged ngspice-27 and compiled ngspice-31+. Ngspice-31+ worked fine but all of a sudden, simulations which used to work fine in KiCAD5.1.4, stopped working and started spitting out
errors like:
Circuit: KiCad schematic
Error on line 0 :
a$poly$e.xx1.egnd %vd [ net-v2-pad1 0 net-v3-pad1 0 ] %vd ( xx1.99 0 ) a$poly$e.xx1.egnd
MIF-ERROR - unable to find definition of model a$poly$e.xx1.egnd
Warning: Model issue on line 0 :
.model a$poly$e.xx1.egnd spice2poly coef = [ 0 .5 .5 ] …
Unknown model type spice2poly - ignored
Error on line 0 :
a$poly$f.xx1.fb %vnam [ v.xx1.vb v.xx1.vc v.xx1.ve v.xx1.vlp v.xx1.vln ] %id ( xx1.7 xx1.99 ) a$poly$f.xx1.fb
MIF-ERROR - unable to find definition of model a$poly$f.xx1.fb
Warning: Model issue on line 0 :
.model a$poly$f.xx1.fb spice2poly coef = [ 0 10.61e6 -10e6 10e6 10e6 -10 …
Unknown model type spice2poly - ignored

So even though KiCAD 5.1.4 has ngspice-30 built in, ngspice-27 seems to be necessary too make things happen.
Of course I could install ngspice-31+ in a separate directory and choose to make ngspice-27 invisible for the users. But I don’t like this workaround because then I’ll have three versions of ngspice on the same system:
ngspice-30 which I don’t now how I to use outside of KiCad5.1.4
ngspice-27 to keep the system working
ngspice-31+ (which I prefer to use from the command line)

Can anyone here suggest a better workaround?

kind regards,
Hugo

Obviously “purging ngspice-27” has removed the XSPICE code model files spice2poly.cm etc. I do not know where they are located typically on a Linux system. Maybe it would be o.k. to re-install KiCad 5.1.4?

You cannot use ngspice coming with KiCad outside of KiCad.

Holger wrote:

“Obviously “purging ngspice-27” has removed the XSPICE code model files spice2poly.cm etc. I do not know where they are located typically on a Linux system. Maybe it would be o.k. to re-install KiCad 5.1.4?Obviously “purging ngspice-27” has removed the XSPICE code model files spice2poly.cm etc. I do not know where they are located typically on a Linux system. Maybe it would be o.k. to re-install KiCad 5.1.4?”

As you suggested I tried reinstalling KiCad5.1 from ppa:reynaud but that did not solve te problem. I still have to apt install ngspice (ngspice-27) even though I am not going to use it. I also considered
manually putting the compiled ngspice-31+ als ngspice31 under /usr/bin but then I get a message
Note: can’t find init file …
each time I start that ngspice31

maybe that last quirk can be solved easily?
kind regards,
Hugo

As you suggested I tried reinstalling KiCad5.1 from ppa:reynaud but that did not solve te problem. I still have to apt install ngspice (ngspice-27) even though I am not going to use it. I also considered
manually putting the compiled ngspice-31+ als ngspice31 under /usr/bin but then I get a message
Note: can’t find init file …
each time I start that ngspice31

maybe that last quirk can be solved easily?

In fact there is no need “to solve that quirk”:
I checked everything again and in fact it is perfectly fine to have both an apt install ngspice
on Mint 19.2 which installs ngspice-27 as /usr/bin/ngspice and a manually compiled ngspice31+ which installs as /usr/local/bin/ngspice. When you enter ngspice, ngspice31+ is found first in the PATH and starts as wanted. However purging or removing ngspice-27 breaks KICAD-simulations as mentioned earlier.

kind regards,
Hugo

Obviously “purging ngspice-27” has removed the XSPICE code model files
spice2poly.cm etc. I do not know where they are located typically on a Linux system.

I found out the following:
apt install ngspice in mint 19.2 installs spice2poly.cm as /usr/lib/ngspice/spice2poly.cm
and
a manually compiled ngspice-31+ (finished by make install)
installs spice2poly.cm as /usr/local/lib/ngspice/spice2poly.cm

Therefore it is also possible to apt purge ngspice (-27) and keep KiCAD5.1-simulations working by adding a link like this:
cd /usr/lib
ln -s /usr/local/lib/ngspice/ .

kind regards,
Hugo

That’s the wrong approach and really ugly. What you want is to expand the scope of the library patch (done by the environment $LD_LIBRARY_PATH) within your local user environment.

Or, if your are more advanced, rebuild a recent ngspice version for your system.

Dear Tijuca,
I know my solution is not the most elegant but at least it is a usable workaround if you
really want to remove ngspice-27 from the Mint 19.2 installation.
I also tried your solution:
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib
But simulation from within KiCad5.1-schematics did not work that way when
XSPICE code model files are needed.

You also wrote “rebuild a recent ngspice version for your system.” I think you overlooked
in the initial mail that I did install ngspice-31+ from source.

Anyway, I can cope with having 3 versions of ngspice on my system even though it is
not an ideal scenario

kind regards,
Hugo

Because the existing (old) library libngspice.so.0 is probably found within the standard path referenced by $LD_LIBRARY_PATH (if set) the library resolver is happy and wont ever try to have a look at /usr/local/lib. And the ngspice library doesn’t have any symbol versioning, no application will ever complain. To be sure the library is used from the desired patch you need to switch both entries so the system will first have a look in /usr/local/lib.

And the export is only done in the current shell session. You can always simply look at the content of such environments by simply echo out the content. I’m quite sure LD_LIBRARY_PATH is/was empty in your session as this is the default.

$ echo $LD_LIBRARY_PATH

You can also simply set the LD_LIBRARY_PATH only for the kicad session to point to some temporary library path. I need to do so for calling test builds of KiCad which are of course not installed into the normal system folders.

LD_LIBRARY_PATH=/home/user/tmp/kicad/lib /home/user/tmp/kicad/bin/kicad

You might have overlooked the former part of that sentence. :slight_smile:

If your are working outside the packaging ecosystem you are completely on your own. Mint isn’t the best system in my eyes if you want or need to follow recent upstream versions as the main focus is to have rather a stable system.