I encountered quite a few issues compiling KiCad 5.1.0 from source that took me a few hours to debug (some spent napping while things compiled). The whole thing is in the end < 20 lines of bash commands, though compilation took me 2-3 hours.
Here’s a tried-and-true method to get it to install (I tested on a VM). You should probably go straight to “install kicad” section.
From the beginning: Virtualbox
To make sure these instructions worked for 18.04.2, I tested on a clean install inside VirtualBox. Here I write down instructions, since some steps were confusing to me when I used Virtualbox for the first time.
- Install virtualbox
- I forget which of these I used… either download and double-click the *.deb, from the links at the very top of the page
- Or follow the instructions add the PPA and install https://www.virtualbox.org/wiki/Linux_Downloads
- Download ubuntu 18.04.2 ISO from https://www.ubuntu.com/download/desktop
- Create new VM
- Machine > New…
- Go though — I used 2048 GB memory and 40 GB virtual (expandable) hard disk
- Install Ubuntu into the VM
- Machine > Settings > Storage > Controller: IDE
- Click the “+” sign over the CD rom
- Choose Disk > Add > (then select your .iso file)
- Now click okay. We’re back to the main window — click the big green “Start” arrow.
- The VM starts up, and the standard “Install Ubuntu” screen should pop up once booted. Install Ubuntu as normal
- Make sure to click “Also install proprietary media” as otherwise “Virtualbox Guest Additions ISO” will later not run
- Machine > Settings > Storage > Controller: IDE
- We probably want to copy-paste in commands. Thus, install Guest Additions. This already comes built-in to virtualbox, no need to download anything else
- Devices > Insert Guest Additions Add-on Image…
- Click “run” when pop-up prompts
- If nothing happens, try running from commandline
cd ~/VBox_GAs_6.0.6 ./autorun.sh install # This should pop up a second terminal, which asks "Do you wish to continue" > "Yes"
- If not, it’ll probably complain about gcc not being installed; run
sudo apt install build-essential
- If nothing happens, try running from commandline
- Restart
sudo shutdown -r now
- Now enable clipboard
- Devices > Clipboard > Bidirectional
- Also, View > Auto-Resize Display should now work, but I turn it off because if you accidentally resize the window your VM could freeze alarmingly
Install KiCad
First let’s install dependencies
sudo add-apt-repository ppa:js-reynaud/kicad-dev-nightly sudo apt-get update sudo apt-get build-dep kicad
This last command will spit out an error — E: You must put some 'source' URIs in your sources.list
— so go to “Software and Updates” and check the “Source Code” on the first tab. Then again run build-dep, as well as install the other dependencies.
$ sudo apt-get build-dep kicad $ sudo apt install libglm-dev $ LibGLM $ sudo apt install liboce-foundation-dev liboce-modeling-dev liboce-ocaf-dev liboce-visualization-dev # OCE files $ sudo apt-get install libboost-all-dev #Boost
Install Ngspice from source
This was a pain to figure out, since it would compile for 10 minutes before failing. Basically, can’t skip independently installing the dependencies, even with the build-dep step above. Fortunately easy to install dependencies.
$ sudo apt-get install autoconf automake bison flex gcc git libtool make # otherwise get 'yacc' errors $ cd ~/kicad/scripting/build_tools $ sudo ./get_libngspice_so.sh *** ngspice shared library has been built successfully! ***Now, to finish the installation run the script as root with 'install' parameter $ sudo ./get_libngspice_so.sh install *** Installation completed successfully! *
Note: Why not apt install? If you just run sudo apt-get install ngspice, later during cmake it will complain about
In file included from /home/lir/kicad/eeschema/sim/ngspice.cpp:28:0: /home/lir/kicad/eeschema/sim/ngspice.h:31:10: fatal error: ngspice/sharedspice.h: No such file or directory
Probably, there’s some symlink solution, but I’ve spent way too long on this already.
Then, install KiCad itself.
We follow http://docs.kicad-pcb.org/doxygen/md_Documentation_development_compiling.html
git clone -b master https://git.launchpad.net/kicad
cd <your kicad source mirror> mkdir -p build/release cd build/release
However, there are some issues (specific to 16.04+ I think) with wxWidgets and wxPython you really don’t want to. Thus we change the cmake line to add options to ignore scripting and things that require wxWidgets / wxPython:
$ cmake -j2 -DCMAKE_BUILD_TYPE=Release -DKICAD_SCRIPTING=OFF -DKICAD_SCRIPTING_MODULES=OFF -DKICAD_SCRIPTING_WXPYTHON=OFF ../../ $ make $ sudo make install
Now you should be able to run kicad from the commandline
$ kicad
Pops up a GUI kicad window!
Appendix
make clean
If something isn’t working that you think should, try clearing old files generated by make
:
$ make clean # clear files $ make # then try again
Note
Useful: You can see what other flags you can provide to cmake (using the -D
flag), by peeking at kicad/build/release/CMakeCache.txt
lir@lir-VM:~/kicad/build/release $ vi CMakeCache.txt [...] KICAD_SCRIPTING_WXPYTHON=OFF [...]
Errors
These are some of the errors I ran into. If you see this, the solution to them is one of the lines above…
ngspice errors
CMake Error at /usr/share/cmake-3.10/Modules/FindPackageHandleStandardArgs.cmake:137 (message):
Could NOT find ngspice (missing: NGSPICE_INCLUDE_DIR)
Call Stack (most recent call first):
/usr/share/cmake-3.10/Modules/FindPackageHandleStandardArgs.cmake:378 (_FPHSA_FAILURE_MESSAGE)
CMakeModules/Findngspice.cmake:57 (find_package_handle_standard_args)
CMakeLists.txt:607 (find_package)
yacc -d -o parse-bison.c parse-bison.y
/bin/bash: yacc: command not found
Makefile:1052: recipe for target 'parse-bison.c' failed
make[3]: *** [parse-bison.c] Error 127
make[3]: Leaving directory '/tmp/libngspice_so/ngspice/src/frontend'
Makefile:773: recipe for target 'install-recursive' failed
make[2]: *** [install-recursive] Error 1
make[2]: Leaving directory '/tmp/libngspice_so/ngspice/src/frontend'
Makefile:1359: recipe for target 'install-recursive' failed
make[1]: *** [install-recursive] Error 1
make[1]: Leaving directory '/tmp/libngspice_so/ngspice/src'
Makefile:434: recipe for target 'install-recursive' failed
make: *** [install-recursive] Error 1
A whole host of wx errors, solved by not using wx ^___^
-- KiCad install dir: </usr/local>
-- Check for installed GLEW -- found
-- Boost version: 1.65.1
-- Found the following Boost libraries:
-- regex
-- Check for installed Python Interpreter -- found
-- Python module install path: lib/python2.7/dist-packages
-- Found wxPython 3.0.2.0/gtk3 (wxWidgets 3.0.2.0)
CMake Error at CMakeLists.txt:780 (message):
Cannot find wxPython.h
*** Could not run GTK+ test program, checking why...
*** The test program failed to compile or link. See the file config.log for the
*** exact error that occured. This usually means GTK+ is incorrectly installed.
configure: error:
The development files for GTK+ were not found. For GTK+ 2, please
ensure that pkg-config is in the path and that gtk+-2.0.pc is
installed. For GTK+ 1.2 please check that gtk-config is in the path,
and that the version is 1.2.3 or above. Also check that the
libraries returned by 'pkg-config gtk+-2.0 --libs' or 'gtk-config
--libs' are in the LD_LIBRARY_PATH or equivalent.
Error running configure
ERROR: failed building wxWidgets
Traceback (most recent call last):
File "build.py", line 1325, in cmd_build_wx
wxbuild.main(wxDir(), build_options)
File "/tmp/pip-build-v_pIAS/wxpython/buildtools/build_wxwidgets.py", line 373, in main
"Error running configure")
File "/tmp/pip-build-v_pIAS/wxpython/buildtools/build_wxwidgets.py", line 85, in exitIfError
raise builder.BuildError(msg)
BuildError
Finished command: build_wx (4.755s)
Finished command: build (4.755s)
Command '"/usr/bin/python" -u build.py build' failed with exit code 1. [ 78%] Building CXX object pcbnew/CMakeFiles/pcbnew_kiface_objects.dir/swig/pcbnew_scripting_helpers.cpp.o
[ 78%] Building CXX object pcbnew/CMakeFiles/pcbnew_kiface_objects.dir/swig/python_scripting.cpp.o
[ 79%] Built target pcbnew_kiface_objects
Makefile:162: recipe for target 'all' failed
make: *** [all] Error 2
wx_python_helpers.cpp:(.text+0x3a1): undefined reference to `PyErr_Occurred'
wx_python_helpers.cpp:(.text+0x5b3): undefined reference to `PyUnicodeUCS4_AsWideChar'
../../pcbnew/CMakeFiles/pcbnew_kiface_objects.dir/__/common/swig/wx_python_helpers.cpp.o: In function `Py2wxString(_object*)':
wx_python_helpers.cpp:(.text+0x929): undefined reference to `PyErr_Clear'
collect2: error: ld returned 1 exit status
qa/pcbnew/CMakeFiles/qa_pcbnew.dir/build.make:929: recipe for target 'qa/pcbnew/qa_pcbnew' failed
make[2]: *** [qa/pcbnew/qa_pcbnew] Error 1
CMakeFiles/Makefile2:3908: recipe for target 'qa/pcbnew/CMakeFiles/qa_pcbnew.dir/all' failed
make[1]: *** [qa/pcbnew/CMakeFiles/qa_pcbnew.dir/all] Error 2
home/lir/kicad/eeschema/dialogs/dialog_spice_model.cpp: In member function ‘bool DIALOG_SPICE_MODEL::addPwlValue(const wxString&, const wxString&)’:
/home/lir/kicad/eeschema/dialogs/dialog_spice_model.cpp:809:70: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
m_pwlValList->SetItemData( idx, *reinterpret_cast<long*>( &timeF ) );
^
[ 41%] Building CXX object eeschema/CMakeFiles/eeschema_kiface_objects.dir/widgets/tuner_slider.cpp.o
[ 41%] Building CXX object eeschema/CMakeFiles/eeschema_kiface_objects.dir/widgets/tuner_slider_base.cpp.o
[ 41%] Building CXX object eeschema/CMakeFiles/eeschema_kiface_objects.dir/__/common/dialogs/dialog_page_settings.cpp.o
[ 41%] Building CXX object eeschema/CMakeFiles/eeschema_kiface_objects.dir/__/common/base_screen.cpp.o
[ 41%] Building CXX object eeschema/CMakeFiles/eeschema_kiface_objects.dir/__/common/base_units.cpp.o
[ 41%] Building CXX object eeschema/CMakeFiles/eeschema_kiface_objects.dir/__/common/eda_text.cpp.o
[ 41%] Building CXX object eeschema/CMakeFiles/eeschema_kiface_objects.dir/__/common/page_info.cpp.o
[ 41%] Built target eeschema_kiface_objects
Makefile:162: recipe for target 'all' failed
make: *** [all] Error 2 [ 34%] Built target idfcyl
[ 35%] Built target idfrect
[ 36%] Built target dxf2idf
In file included from /home/lir/kicad/eeschema/sim/ngspice.cpp:28:0:
/home/lir/kicad/eeschema/sim/ngspice.h:31:10: fatal error: ngspice/sharedspice.h: No such file or directory
#include <ngspice/sharedspice.h>
^~~~~~~~~~~~~~~~~~~~~~~
compilation terminated.
eeschema/CMakeFiles/eeschema_kiface_objects.dir/build.make:4709: recipe for target 'eeschema/CMakeFiles/eeschema_kiface_objects.dir/sim/ngspice.cpp.o' failed
make[2]: *** [eeschema/CMakeFiles/eeschema_kiface_objects.dir/sim/ngspice.cpp.o] Error 1
CMakeFiles/Makefile2:1087: recipe for target 'eeschema/CMakeFiles/eeschema_kiface_objects.dir/all' failed
make[1]: *** [eeschema/CMakeFiles/eeschema_kiface_objects.dir/all] Error 2
make[1]: *** Waiting for unfinished jobs....
[ 37%] Built target kicad2step_lib
Makefile:162: recipe for target 'all' failed
make: *** [all] Error 2
Thanks
I figured most of this out from two forum posts:
https://bugs.launchpad.net/kicad/+bug/1804771
https://forum.kicad.info/t/wxpython-3-1-error-building-kicad-from-source-ubuntu-18-04/11431
$ make clean # clear files $ make # then try again
Note
Useful: You can see what other flags you can provide to cmake (using the -D
flag), by peeking at kicad/build/release/CMakeCache.txt
lir@lir-VM:~/kicad/build/release $ vi CMakeCache.txt [...] KICAD_SCRIPTING_WXPYTHON=OFF [...]
Errors
These are some of the errors I ran into. If you see this, the solution to them is one of the lines above…
ngspice errors
CMake Error at /usr/share/cmake-3.10/Modules/FindPackageHandleStandardArgs.cmake:137 (message):
Could NOT find ngspice (missing: NGSPICE_INCLUDE_DIR)
Call Stack (most recent call first):
/usr/share/cmake-3.10/Modules/FindPackageHandleStandardArgs.cmake:378 (_FPHSA_FAILURE_MESSAGE)
CMakeModules/Findngspice.cmake:57 (find_package_handle_standard_args)
CMakeLists.txt:607 (find_package)
yacc -d -o parse-bison.c parse-bison.y
/bin/bash: yacc: command not found
Makefile:1052: recipe for target 'parse-bison.c' failed
make[3]: *** [parse-bison.c] Error 127
make[3]: Leaving directory '/tmp/libngspice_so/ngspice/src/frontend'
Makefile:773: recipe for target 'install-recursive' failed
make[2]: *** [install-recursive] Error 1
make[2]: Leaving directory '/tmp/libngspice_so/ngspice/src/frontend'
Makefile:1359: recipe for target 'install-recursive' failed
make[1]: *** [install-recursive] Error 1
make[1]: Leaving directory '/tmp/libngspice_so/ngspice/src'
Makefile:434: recipe for target 'install-recursive' failed
make: *** [install-recursive] Error 1
A whole host of wx errors, solved by not using wx ^___^
-- KiCad install dir: </usr/local>
-- Check for installed GLEW -- found
-- Boost version: 1.65.1
-- Found the following Boost libraries:
-- regex
-- Check for installed Python Interpreter -- found
-- Python module install path: lib/python2.7/dist-packages
-- Found wxPython 3.0.2.0/gtk3 (wxWidgets 3.0.2.0)
CMake Error at CMakeLists.txt:780 (message):
Cannot find wxPython.h
*** Could not run GTK+ test program, checking why...
*** The test program failed to compile or link. See the file config.log for the
*** exact error that occured. This usually means GTK+ is incorrectly installed.
configure: error:
The development files for GTK+ were not found. For GTK+ 2, please
ensure that pkg-config is in the path and that gtk+-2.0.pc is
installed. For GTK+ 1.2 please check that gtk-config is in the path,
and that the version is 1.2.3 or above. Also check that the
libraries returned by 'pkg-config gtk+-2.0 --libs' or 'gtk-config
--libs' are in the LD_LIBRARY_PATH or equivalent.
Error running configure
ERROR: failed building wxWidgets
Traceback (most recent call last):
File "build.py", line 1325, in cmd_build_wx
wxbuild.main(wxDir(), build_options)
File "/tmp/pip-build-v_pIAS/wxpython/buildtools/build_wxwidgets.py", line 373, in main
"Error running configure")
File "/tmp/pip-build-v_pIAS/wxpython/buildtools/build_wxwidgets.py", line 85, in exitIfError
raise builder.BuildError(msg)
BuildError
Finished command: build_wx (4.755s)
Finished command: build (4.755s)
Command '"/usr/bin/python" -u build.py build' failed with exit code 1. [ 78%] Building CXX object pcbnew/CMakeFiles/pcbnew_kiface_objects.dir/swig/pcbnew_scripting_helpers.cpp.o
[ 78%] Building CXX object pcbnew/CMakeFiles/pcbnew_kiface_objects.dir/swig/python_scripting.cpp.o
[ 79%] Built target pcbnew_kiface_objects
Makefile:162: recipe for target 'all' failed
make: *** [all] Error 2
wx_python_helpers.cpp:(.text+0x3a1): undefined reference to `PyErr_Occurred'
wx_python_helpers.cpp:(.text+0x5b3): undefined reference to `PyUnicodeUCS4_AsWideChar'
../../pcbnew/CMakeFiles/pcbnew_kiface_objects.dir/__/common/swig/wx_python_helpers.cpp.o: In function `Py2wxString(_object*)':
wx_python_helpers.cpp:(.text+0x929): undefined reference to `PyErr_Clear'
collect2: error: ld returned 1 exit status
qa/pcbnew/CMakeFiles/qa_pcbnew.dir/build.make:929: recipe for target 'qa/pcbnew/qa_pcbnew' failed
make[2]: *** [qa/pcbnew/qa_pcbnew] Error 1
CMakeFiles/Makefile2:3908: recipe for target 'qa/pcbnew/CMakeFiles/qa_pcbnew.dir/all' failed
make[1]: *** [qa/pcbnew/CMakeFiles/qa_pcbnew.dir/all] Error 2
home/lir/kicad/eeschema/dialogs/dialog_spice_model.cpp: In member function ‘bool DIALOG_SPICE_MODEL::addPwlValue(const wxString&, const wxString&)’:
/home/lir/kicad/eeschema/dialogs/dialog_spice_model.cpp:809:70: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
m_pwlValList->SetItemData( idx, *reinterpret_cast<long*>( &timeF ) );
^
[ 41%] Building CXX object eeschema/CMakeFiles/eeschema_kiface_objects.dir/widgets/tuner_slider.cpp.o
[ 41%] Building CXX object eeschema/CMakeFiles/eeschema_kiface_objects.dir/widgets/tuner_slider_base.cpp.o
[ 41%] Building CXX object eeschema/CMakeFiles/eeschema_kiface_objects.dir/__/common/dialogs/dialog_page_settings.cpp.o
[ 41%] Building CXX object eeschema/CMakeFiles/eeschema_kiface_objects.dir/__/common/base_screen.cpp.o
[ 41%] Building CXX object eeschema/CMakeFiles/eeschema_kiface_objects.dir/__/common/base_units.cpp.o
[ 41%] Building CXX object eeschema/CMakeFiles/eeschema_kiface_objects.dir/__/common/eda_text.cpp.o
[ 41%] Building CXX object eeschema/CMakeFiles/eeschema_kiface_objects.dir/__/common/page_info.cpp.o
[ 41%] Built target eeschema_kiface_objects
Makefile:162: recipe for target 'all' failed
make: *** [all] Error 2 [ 34%] Built target idfcyl
[ 35%] Built target idfrect
[ 36%] Built target dxf2idf
In file included from /home/lir/kicad/eeschema/sim/ngspice.cpp:28:0:
/home/lir/kicad/eeschema/sim/ngspice.h:31:10: fatal error: ngspice/sharedspice.h: No such file or directory
#include <ngspice/sharedspice.h>
^~~~~~~~~~~~~~~~~~~~~~~
compilation terminated.
eeschema/CMakeFiles/eeschema_kiface_objects.dir/build.make:4709: recipe for target 'eeschema/CMakeFiles/eeschema_kiface_objects.dir/sim/ngspice.cpp.o' failed
make[2]: *** [eeschema/CMakeFiles/eeschema_kiface_objects.dir/sim/ngspice.cpp.o] Error 1
CMakeFiles/Makefile2:1087: recipe for target 'eeschema/CMakeFiles/eeschema_kiface_objects.dir/all' failed
make[1]: *** [eeschema/CMakeFiles/eeschema_kiface_objects.dir/all] Error 2
make[1]: *** Waiting for unfinished jobs....
[ 37%] Built target kicad2step_lib
Makefile:162: recipe for target 'all' failed
make: *** [all] Error 2
Thanks
I figured most of this out from two forum posts:
https://bugs.launchpad.net/kicad/+bug/1804771
https://forum.kicad.info/t/wxpython-3-1-error-building-kicad-from-source-ubuntu-18-04/11431