Build KiCad from source on Linux

OS: Kubuntu 22.04

Hello!

Background

I want to install several versions on my Linux system, but KiCad seems to use hard coded paths and these are the same for all versions, so parallel use of various main versions is not possible. I noticed that there are build options for the paths, so I decided to try building KiCad for myself. I started with KiCad 7.

What I did

Problem

I run the commands in the first box: Linux | Developer Documentation | KiCad
I got this error message:

...
-- Checking for module 'ngspice'
--   No package 'ngspice' found

*** NGSPICE library missing ***
Most of ngspice packages do not provide the required libngspice library.
You can either compile ngspice configured with --with-ngshared parameter
or run a script that does the job for you:
  cd ./tools/build
  chmod +x get_libngspice_so.sh
  ./get_libngspice_so.sh
  sudo ./get_libngspice_so.sh install

CMake Error at /usr/share/cmake-3.25/Modules/FindPackageHandleStandardArgs.cmake:230 (message):
  Could NOT find ngspice (missing: NGSPICE_INCLUDE_DIR)
Call Stack (most recent call first):
  /usr/share/cmake-3.25/Modules/FindPackageHandleStandardArgs.cmake:600 (_FPHSA_FAILURE_MESSAGE)
  cmake/Findngspice.cmake:162 (find_package_handle_standard_args)
  CMakeLists.txt:803 (find_package)

I thought ngspice is installed, but installing libngspice0 and libngspice0-dev with apt solved it. Now the error is:

...
-- Checking for module 'ngspice'
--   Found ngspice, version 36
-- Found ngspice: /usr/include  
-- Found OCC: /usr/include/opencascade (found version "7.5.2") 

*** OpenCascade library missing ***
Could not find a library for TKBinXCAF at /usr/lib/x86_64-linux-gnu
Verify your OpenCascade installation or pass CMake
  the library directory as '-DOCC_LIBRARY_DIR=<path>'

CMake Error at cmake/FindOCC.cmake:192 (message):
Call Stack (most recent call first):
  CMakeLists.txt:807 (find_package)

Before I install any further package … What’s the problem? Missing packages or incorrect paths? Is there any advice? Thanks!

3 Likes

Wow, thanks! I got 7.0.9 compiled with the default settings and it works on the first try :slight_smile:

Now I try to change the path and then to compile the latest 6.0 and 5.1.

Currently I’m testing with KiCad 6.0.

Changing the path to /opt/kicad/6.0 worked (for 7.0.9). With “make install” all created files are in /opt/kicad/6.0 and I can copy them all together. I made a deb package with these files and I put the “Depends” list of the original kicad 6.0.11 deb package into the control file of my deb package.

When I want to execute the kicad binary, I got the message that there is libwx_gtk3u… is missing. After manual installation of the WX libs the kicad binary starts and also eeschema, but pcbnew doesn’t work, like you wrote in your tutorial. I got this error message:

Failed to load shared library ‘/opt/kivad/6.0/bin/_psbnew.kiface’:
libkicad.3dsg.so.2.0.0: cannot open shared object file: No such file or directory

On a system with the official kicad 6 installed, this file is located at /usr/lib/x86_64-linux-gnu/, but here it is located at /opt/kicad/6.0/lib/. After adding this path to /etc/ld.so.conf.d/libc.conf, it worked.

And now my question:
Is there a (easy) way that kicad knows this path, but not the whole system? Or is there any path kicad looks into by default, where I can put the files into?

When there is more than one version installed, I get a conflict if I put the file to the global path in /usr/lib or if the file is located at /opt/kicad/x.0/, but for every kicad version there is an entry in /etc/ld.so.conf.d/.

I want to create a (single) deb file, which allows to start kicad without using the shell or adding any repositories.

That’s what LD_LIBRARY_PATH is made for.

LD_LIBRARY_PATH=/path/to/additional/lib-folder /path/to/your/binary-which-needs-exact-this-extra-lib-path

I use a alias to start my manual created binary.

Thank you for your answer. What do I have to do with LD_LIBRARY_PATH? I don’t really understand this.

All explanations I found say, that I have to execute “export LD_LIBRARY_PATH= /path/to/additional/lib-folder” and then it hase the same effect as adding /path/to/additional/lib-folder to a file in /path/to/additional/lib-folder. It affects all binaries. KiCad 7.0 would search at the same path.

I can’t find documentation for adding a path to a binary for the library and it doesn’t work:

vboxuser@VBox-KiCad-Test:/opt/kicad/6.0/bin$ export LD_LIBRARY_PATH=/opt/kicad/6.0/lib /opt/kicad/6.0/bin/pcbnew
bash: export: `/opt/kicad/6.0/bin/pcbnew’: not a valid identifier

What did I wrong?

Update: To get hardcoded links, the command

strings /opt/kicad/6.0/bin/kicad | grep /opt

returns:

/opt/kicad/6.0/share/kicad
/opt/kicad/6.0/lib
/opt/kicad/6.0/share/doc/kicad

So the folder “/opt/kicad/6.0/lib” seems to be hardcoded for libraries. So shouldn’t that work without doing anything?

Now I got it. It’s easier than I thought … I don’t know why all descriptions I found for this environment variable are only describing the allocation of this variable without the path to the binary. I didn’t know that it’s possible to execute a binary with a privious allocation.

For the other people, here a description what I did and what I understand.
Setting LD_LIBRARY_PATH to the library path and then open the binary with the next command has no effect:

LD_LIBRARY_PATH=/opt/kicad/6.0/lib
/opt/kicad/6.0/bin/pcbnew

Writing this in one line works:

LD_LIBRARY_PATH=/opt/kicad/6.0/lib /opt/kicad/6.0/bin/pcbnew

If I execute kicad instead of pcbnew and then open pcbnew via kicad then it also works, so there seems to be a chain, the environment variables apply for all binaries that were open from the first binary.
Instead of a symbolic link I created a shell script /usr/bin/kicad6.0 with this content:

#!/bin/sh
LD_LIBRARY_PATH=/opt/kicad/6.0/lib /opt/kicad/6.0/bin/kicad

Result: The command kicad6.0 starts KiCad like I want.

1 Like

Sure. That’s the way environment variables work in Linux shells in general. If a setting is not exported, then its scope ends at the end of statement and is just an ordinary shell variable, not an environment variable. However exporting it will cause the setting to be used by all future commands, interfering with other commands that don’t want the setting. That’s why the command has to follow the setting on the same line. Environment variables are inherited by child processes.

1 Like

I have one note for this script line. It should contain “$1” at the end to allow opening files directly by double click to the file.

#!/bin/sh
LD_LIBRARY_PATH=/opt/kicad/6.0/lib /opt/kicad/6.0/bin/kicad “$1”

Environment variables work but may be clumsy in some cases. In my instruction page linked to above I describe how to set the library path for the system. It depends on the system but should be easy. Whether somebody wants it that way or not is a system administration decision.

If I use the library path for the system, then it’s not posible to use two different KiCad versions on one system, as there will be collisions. Or am I wrong?

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.