Compiling on Linux
Documented platforms
The documentation here covers Debian/Ubuntu and Flatpak. Debian .deb packages and Flatpaks is the primary deployment platforms for Linux. It is certainly possible to compile OpenCPN on other Linux distributions by adapting these instructions.
The instructions are based on the files in the ci/ directory, at the time of writing ci/generic_build_debian.sh and ci/generic_build_flatpak.sh. These files which are continously tested is the ultimate source for how to build on Linux.
Debian/Ubuntu
1. Install build dependencies
$ sudo apt install devscripts equivs $ sudo mk-build-deps -i -r ci/control $ sudo apt-get --allow-unauthenticated install -f
For Ubuntu-focal :
$ sudo apt install devscripts equivs $ sudo mk-build-deps -i -r ci/control-focal-gtk3 $ sudo apt-get --allow-unauthenticated install -f
Notes:
-
On Debian Buster and Ubuntu Bionic it is possible to build OpenCPN linked against gtk2 or gtk3. The default alternative is to use gtk2.
-
The build setup is generally updated for Debian and Ubuntu LTS releases.
4. Build it
We’ll build everything in a subdirectory to keep the codebase clean (easier to catch changes).
$ cd OpenCPN $ mkdir build $ cd build $ cmake .. $ make
Notes:
Default install dir is /usr/local, this can be changed by providing the appropriate option to cmake:
$ cmake -DCMAKE_INSTALL_PREFIX=/usr ..
cmake is only required when building source code for the first time, then running make is enough even if the source code is updated.
Flatpak
1. Install flatpak
Install flatpak and flatpak-builder as described in https://flatpak.org/setup/.
2. Install runtime and SDK
At the time of writing version 18.08 is used. Check flatpak/org.opencpn.OpenCPN.yaml for the version actually used, look for runtime-version:. Install the proper runtime and Sdk, for example:
$ sudo flatpak install flathub org.freedesktop.Platform//18.08 $ sudo flatpak install flathub org.freedesktop.Sdk//18.08
5. Debugging
The flatpak’ed OpenCPN runs in a sandbox, so specialized debugging techniques must be applied. See The flatpak site
The makefile will build the flatpak version and also install it.
Compiling for Raspberry Pie (rPI)
From rPI 4 the board has resources enough to run a native build, which is performed according to the instructions for Debian. At the time of writing, it is unclear if this is possible on a rPI 3 with 1MB of RAM.
Fixme |
IDEs
It is possible to use various IDEs to edit OpenCPN’s code on Linux. Choosing one of Code::Blocks, KDevelop or Eclipse CDT simplifies since cmake supports generating their project files. To this end replace the cmake configuration step with one of the following, corresponding to the used IDE. In all cases it will still be possible to do the commandline build as described above.
$ cmake -G "CodeBlocks - Unix Makefiles" ../
$ cmake -G "KDevelop3 - Unix Makefiles" ../
$ cmake -G "Eclipse CDT4 - Unix Makefiles" ../
To prototype the GUI parts of the application, have a look a wxFormBuilder.
In order to be able to run OpenCPN from inside the IDE without having it installed data needs to be copied to the build/ folder according to
$ cd build $ for d in gshhs s57data tcdata; do; cp -ar ../data/$d .; done $ mkdir uidata $ cp ../src/bitmaps/*.xml ../src/bitmaps/*.png ../src/bitmaps/*.svg uidata $ cp ../data/authors.html ../data/license.html .
opencpn should be run with the -p options which sets it into 'portable' mode and therefore looks in the location the 'opencpn' executable is run from, i.e. the 'build' directory.