Difference between revisions of "Building on Windows"

From GnuCash
Jump to: navigation, search
(GnuCash Windows - Development Notes: Add environment instructions, indicate guile 1.8 is sorted.)
(Running a build: Note about WebKitGtk)
 
(54 intermediate revisions by 11 users not shown)
Line 1: Line 1:
== GnuCash Windows - Development Notes ==
+
Development on Microsoft Windows isn't really encouraged. The build environment isn't really conducive to development and many of the unit tests don't work. However, if you must...
== Working on Gnucash ==
 
Once you've successfully built Gnucash and all of its dependencies, it's a bit of a pain to re-run install.sh after every edit. To use <tt>make</tt> from the command prompt as usual, you need to set the following environment:
 
export OLDPATH=$PATH
 
 
PATH=/c/soft/svn/bin:$PATH
 
PATH=/c/soft/autotools/bin:$PATH
 
PATH=/c/soft/swig:$PATH
 
PATH=$PATH:/c/soft/active-perl/ActivePerl/perl/bin
 
PATH=$PATH:/c/soft/aqbanking/bin
 
PATH=$PATH:/c/soft/gwenhywfar/bin
 
PATH=$PATH:/c/soft/autotools/bin
 
PATH=$PATH:/c/soft/enchant/bin
 
PATH=$PATH:/c/soft/gmp/bin
 
PATH=$PATH:/c/soft/gnome/bin
 
PATH=$PATH:/c/soft/gnutls/bin
 
PATH=$PATH:/c/soft/goffice/bin
 
PATH=$PATH:/c/soft/guile/bin
 
PATH=$PATH:/c/soft/libdbi/bin
 
PATH=$PATH:/c/soft/libgsf/bin
 
PATH=$PATH:/c/soft/libofx/bin
 
PATH=$PATH:/c/soft/libsoup/bin
 
PATH=$PATH:/c/soft/libxslt/bin
 
PATH=$PATH:/c/soft/mysql/bin
 
PATH=$PATH:/c/soft/mysql/lib
 
PATH=$PATH:/c/soft/opensp/bin
 
PATH=$PATH:/c/soft/pcre/bin
 
PATH=$PATH:/c/soft/pgsql/bin
 
PATH=$PATH:/c/soft/pgsql/lib
 
PATH=$PATH:/c/soft/regex/bin
 
PATH=$PATH:/c/soft/sqlite3/bin
 
PATH=$PATH:/c/soft/webkit/bin
 
 
export PATH
 
 
export LTDL_LIBRARY_PATH=/c/soft/gnucash/inst/lib
 
export GNOME2_PATH=/c/soft/gnome
 
export INTLTOOL_PERL=/c/soft/active-perl/ActivePerl/perl/bin/perl
 
export GIT_CMD=/c/soft/git/git
 
export ACLOCAL_FLAGS="-I/c/soft/guile/share/aclocal -I/c/soft/gwenhywfar/share/aclocal -I/c/soft/aqbanking/share/aclocal -I/c/soft/autotools/share/aclocal -I/c/soft/gnome/share/aclocal -I/c/soft/gnutls/share/aclocal"
 
  
I put all of those commands into a file called <tt>devrc</tt> and then source it into my shell:
+
= GnuCash 3.0 and Later =
. devrc
 
<tt>$OLDPATH</tt> is there so that you can reset the path easily:
 
export PATH=$OLDPATH
 
  
The other piece of the puzzle is that you need to specify some environment to configure. Paste the following into a file (in your top-level source directory) -- I call mine <tt>.configure</tt>:
+
The build system for GnuCash 2.7 and later supports Windows 7 and later. The procedure is a bit simpler than for GnuCash 2.6 and earlier and provides a somewhat easier to use development environment. That doesn't mean that we ''recommend'' that you use Windows for development: GnuCash is very much a Unix program and development is much easier in a Unix environment like Linux, BSD, or MacOS.
./configure \
 
    --prefix=/c/soft/gnucash-inst \
 
    --enable-aqbanking \
 
    --enable-ofx \
 
    --enable-debug \
 
    --enable-schemas-install=no \
 
    --enable-dbi \
 
    --with-dbi-dbd-dir=/c/soft/libdbi-drivers/lib/dbd \
 
    --enable-binreloc \
 
    --enable-locale-specific-tax \
 
    CPPFLAGS="$CPPFLAGS -I/c/soft/autotools/include -I/c/soft/regex/include -I/c/soft/gnome/include -I/c/soft/guile/include -I/c/soft/libdbi/include -I/c/soft/gmp/include -I/c/soft/gwenhywfar/include -I/c/soft/libsoup/include -D_WIN32 -ggdb3 -Wall -Werror -fno-builtin-dgettext -fno-builtin-towupper -fno-builtin-iswlower" \
 
    LDFLAGS="$LDFLAGS -L/c/soft/autotools/lib -L/c/soft/regex/lib -L/c/soft/gnome/lib -L/c/soft/guile/lib -L/c/soft/libdbi/lib -L/c/soft/gmp/lib -L/c/soft/gwenhywfar/lib -L/c/soft/libsoup/lib -L/c/soft/enchant/lib -L/c/soft/libxslt/lib -L/c/soft/sqlite3/lib" \
 
      PKG_CONFIG_PATH=/c/soft/autotools/lib/pkgconfig:/c/soft/regex/lib/pkgconfig:/c/soft/gnome/lib/pkgconfig:/c/soft/guile/lib/pkgconfig:/c/soft/libdbi/lib/pkgconfig:/c/soft/gmp/lib/pkgconfig:/c/soft/gwenhywfar/lib/pkgconfig:/c/soft/libsoup/lib/pkgconfig:/c/soft/aqbanking/lib/pkgconfig:/c/soft/libofx/lib/pkgconfig:/c/soft/isocodes/lib/pkgconfig:/c/soft/libonoboui/lib/pkgconfig:/c/soft/libgsf/lib/pkgconfig:/c/soft/libxslt/lib/pkgconfig:/c/soft/webkit/lib/pkgconfig:/c/soft/enchant/lib/pkgconfig:/c/soft/gnutls/lib/pkgconfig:/c/soft/goffice/lib/pkgconfig
 
  
Then you call <tt>.configure</tt> instead of <tt>configure</tt> before you run <tt>make</tt>
+
== PowerShell ==
  
=== Guile 1.8 ===
+
The build system relies heavily on Windows PowerShell.
The following is obsolete: The build scripts for 2.4 and trunk correctly build Guile 1.8. The notes are retained for historical interest.
 
  
GnuCash/Windows currently uses guile 1.6.x. Guile's development continues and the use of this old, no longer supported version of guile is blocking some improvements. Recent examples of this were:
+
:'''Windows 7:''' The PowerShell version that ships with Windows 7 by default is too old. To build GnuCash on that platform a more recent version of [https://docs.microsoft.com/en-us/powershell/scripting/install/installing-windows-powershell?view=powershell-6#upgrading-existing-windows-powershell PowerShell] should be installed. PowerShell version 5.1 is known to work well.
* Guile 1.8.7 removed some deprecated functions. However, the replacement functions were not available in 1.6.x. Because of this, GnuCash has to carry a compatibility header. We were lucky to get away with that.
 
* Andy Wingo provided patches to make GnuCash work with the upcoming guile 2.0 and to remove our dependency on slib. These patches are incompatible with guile 1.6.x (and likely will always be), so they couldn't all be applied.
 
  
I have been attempting for some time to build a more recent version of guile but this turns out to be rather difficult. At the time of this writing, I have a working guile, save it won't load slib. There were many small things I had to do to get to this point. In order not to forget them, I've chosen to document them here.
+
Depending on your security settings you may need to enable running scripts on your computer. For this open a powershell with Administrator privilages and run: <syntaxhighlight lang="powershell">set-executionpolicy unrestricted</syntaxhighlight>
  
==== Getting it to build ====
+
== Bootstrap the build environment ==
The 1.8.7 tarball you can download from guile's homepage won't build in our GnuCash mingw/MSYS environment.
 
  
* First error is that our version of automake is too old. Guile requires 1.11, GnuCash still builds with 1.10 at the time of this writing. Luckily, this can easily be fixed by updating the version in defaults.sh and rebuilding the autotools/libtool packages.
+
First download and run [https://github.com/Gnucash/gnucash-on-windows/blob/master/setup-mingw64.ps1 setup-mingw64.ps1]. Depending on where you want to put the development tree you may need to run PowerShell as an administrator. Once you've downloaded the script start PowerShell. You can review the script's parameters with <syntaxhighlight lang="powershell">help \path\to\setup-mingw64.ps1</syntaxhighlight> For convenience they're
* Guile 1.8.7 no longer contains its own libltdl implementation. This is provided with libtool though. All it required to fix this was to add the proper paths to CPPFLAGS and LDFLAGS.
+
* target_dir: The root directory where the build environment will be installed. The default is c:\gcdev64, but you can put it anywhere you have write privilege.
* Also new is that guile now requires gmp. Another addition to CPPFLAGS and LDFLAGS solves this.
+
* download_dir: Defaults to target_dir\downloads. There's no requirement to have it in target_dir.
* Next is libintl. GnuCash builds this as part of the Gnome packages. However, we pull in the gnome libraries '''after''' we build guile. This doesn't work. So the build script has to be modified to first do the gnome install and then build guile.
+
* x86_64: Set this to $true if you want to build 64-bit binaries. The default is $false, and the developers do not often try to build 64-bit binaries so doing so isn't guaranteed to work nor are the developers much inclined to prioritize fixing it if it doesn't.
* Guile 1.8.7 still recognizes the configure time option --disable-networking, yet it won't build on Windows if this option is set. So this option should be '''removed''' from the build script.
 
* Next, all kinds of unresolved symbol errors pop up. To fix most of them, I looked at the source package of MSYS-guile-1.8.7. They apparently managed to build guile, so it provided a good starting point. I can't use their patches verbatim, because that would result in a guile package that depends on the MSYS environment. Their patch for config.in was very useful though. To build build with this patch, the configure script has to be rebuilt, using autoreconf. This in itself was a bit of a quest. It wouldn't work unless I redefined ACLOCAL and passed autoreconf a number of library paths.
 
* I also learned from the MSYS-guile project that guile should be built with "-Wl,enable-auto-import" to avoid a number of linker warnings (which are treated as errors in our build process).
 
  
That was about all to get the library and executable to build. But then it really gets ugly. The next part of the guile build process uses the freshly compiled executable to setup other required bits. This fails miserably with a rather cryptic error <pre>ERROR: In procedure scm_i_lreadparen: #<unknown port>:1:7: end of file</pre>.
+
:'''Note:''' The help command above will only work if the security settings of your system allow this script to be run. In addition to the ''set-executionpolicy'' command above you may have to run <syntaxhighlight lang="powershell">unblock-file \path\to\setup-mingw64.ps1</syntaxhighlight> before help will work.
  
It took me quite a while to grasp this one. I found several threads on different mailing lists about the error, which where more or less helpful:
+
Once setup-mingw64.ps1 is complete you will have an [http://www.msys2.org/ MSYS2] environment with all of the GnuCash dependencies that don't need to be built from source installed in it.
* http://www.mail-archive.com/bug-guile@gnu.org/msg04711.html, which at some point links to http://lists-archives.org/mingw-users/14268-problem-with-argc-argv-under-msys.html, which in turn refers to http://thread.gmane.org/gmane.comp.gnu.mingw.msys/3719. The solution mentioned here, didn't apply in my case, but I got to understand the problem a little better.
 
* Then I was lucky enough to stumble upon two thread in the mingw-devel list: [http://lists.gnu.org/archive/html/guile-devel/2009-03/msg00098.html Again on windows support] and [http://lists.gnu.org/archive/html/guile-devel/2009-06/msg00193.html Again on windows support (2)]. These are two long threads on building guile on windows and the issues in it. I learned here that the build process uses a wrapper program around the guile executable. Confusingly, this wrapper is called guile.exe as well, yet it has issues on windows, that the actual guile.exe doesn't have. So I wrote a small patch to use that actual guile.exe instead of the wrapper during the build process.
 
  
'''Result''': the guile build process completes, and the guile binary works - provided it can find all of its library dependencies of course.
+
== Running a build ==
<pre>guile -c '(use-modules (srfi srfi-39))'</pre> runs with no problems.
 
  
==== slib ====
+
Next open the Start menu and navigate to MSYS2 64Bit or MSYS2 32Bit; which you want will depend upon the bitness of your Windows version. If you specified x86_64 $true to setup-mingw64.ps1 you'll want to start the mingw64 shell, otherwise the mingw32 shell.
 +
;Note: Currently [2024-07] WebKitGtk is only [{{URL:SF}}projects/gnucash/files/Dependencies/ availabe] in 32-bit and won't link with a 64-bit GnuCash.
 +
In that shell window navigate to the gnucash-on-windows.git directory in the target directory to specified to setup-mingw64.ps1. We'll use the default for the following examples.
 +
<syntaxhighlight lang="bash">
 +
  cd /c/gcdev64/src/gnucash-on-windows.git
 +
  TARGET=gnucash-unstable jhbuild -f jhbuildrc build
 +
</syntaxhighlight>
 +
One of the things setup-mingw64.ps1 did was checkout the rest of the gnucash-on-windows repository in target_dir/src/gnucash-on-windows.git. That contains a customization (python) script and a [https://developer.gnome.org/jhbuild/stable/ jhbuild] moduleset. The customization script selects one of the three GnuCash branches to build based on the value of $TARGET; the possibilities are <tt>gnucash-stable</tt> (the default), <tt>gnucash-unstable</tt> (the unstable release git branch) and <tt>gnucash-releases</tt>, which builds GnuCash from the tarball specified in gnucash.modules instead of from a git branch.The first time <tt>jhbuild build</tt> command will build GnuCash, GnuCash Docs, and all of the dependencies that Mingw-w64 doesn't provide. After that it only builds modules that need rebuilding unless you tell it otherwise; see the [https://developer.gnome.org/jhbuild/stable/ jhbuild manual] for details on controlling jhbuild.
  
This is still problematic at this point.
+
You can start a subshell with the paths to hand-compile or run GnuCash from the command line with <syntaxhighlight lang="bash">TARGET=gnucash-unstable jhbuild -f jhbuildrc shell</syntaxhighlight> This is convenient for development as one can navigate to the gnucash build directory and re-run CMake and make as necessary while developing. '''''N.B.''''' Be sure to use a programming editor that preserves line ending style; git can get really unhappy if you put the wrong kind of line endings into a file.
<pre>guile -c "(use-modules (ice-9 slib)) (require 'printf)"</pre> results in this error:
 
ERROR: In procedure open-file:
 
ERROR: No such file or directory: "C:/GCDevel/guile/share/guile/1.8/slib/C:/GCDevel/guile/share/guile/1.8/slib/require"
 
ABORT: (system error)</pre>
 
  
Obviously there's something wrong with the path guile uses to find the file require.scm.
+
To build a package for installation there's a PowerShell script called <tt>gnucash-on-windows.git\bundle-gnucash.ps1</tt> and an automation script, <tt>gnucash-on-windows.git\buildserver\build_package.ps1</tt> suitable for use with the Task Scheduler for periodic builds. Each includes documentation accessible with PowerShell's <tt>help</tt> command, e.g. <syntaxhighlight lang="powershell">help bundle-gnucash.ps1</syntaxhighlight>
  
I'm still investigating what happens here.
+
Note that <tt>build_package.ps1</tt> also takes care of updating the gnucash-on-windows repository and that <tt>jhbuild build</tt> will update the gnucash repository; you can do so manually with git from within the Mingw shell. SSH works, just set up your ~/.ssh directory with the necessary keys and config file.
 +
 
 +
You may find the [https://github.com/msys2/msys2/wiki MSys2 Wiki] and [https://mingw-w64.org/doku.php/documentation Mingw-w64 Documentation] helpful.
 +
 
 +
== Debugging a build ==
 +
GDB can be used on windows without too much effort.  Usually it's better to attach to an already running process instead of trying to launch directly under GDB.  Ctrl+C does not work as well under GDB, however this site has a workaround: [http://www.mingw.org/wiki/Workaround_for_GDB_Ctrl_C_Interrupt Workaround for GDB Ctrl C Interrupt]
 +
 
 +
Microsoft's Visual Studio Code is a possibility to integrate with gnucash and gdb for debugging.  The following launch.json file can be used to debug with gdb under vscode:
 +
<syntaxhighlight lang="json">
 +
{
 +
    "version": "0.2.0",
 +
    "configurations": [
 +
        {
 +
            "name": "(gdb) launch",
 +
            "type": "cppdbg",
 +
            "request": "launch",
 +
            "program": "C:\\gcdev64\\gnucash\\maint\\inst\\bin\\gnucash.exe",
 +
            "args": [],
 +
            "stopAtEntry": true,
 +
            "cwd": "${workspaceFolder}",
 +
            "environment": [],
 +
            "externalConsole": true,
 +
            "MIMode": "gdb",
 +
            "miDebuggerPath": "C:\\gcdev64\\msys2\\mingw32\\bin\\gdb.exe",
 +
            "setupCommands": [
 +
                {
 +
                    "description": "Enable pretty-printing for gdb",
 +
                    "text": "-enable-pretty-printing",
 +
                    "ignoreFailures": true
 +
                }
 +
            ]
 +
        }
 +
    ]
 +
}
 +
</syntaxhighlight>
 +
 
 +
= GnuCash 2.6 and Earlier =
 +
 
 +
'''GnuCash 2.6 is no longer being developed. This procedure is archival. Don't use it without good reason.'''
 +
 
 +
First read the README for the [https://github.com/Gnucash/gnucash-on-windows Windows Build Environment]. You'll need to download and run [https://github.com/Gnucash/gnucash-on-windows/blob/master/bootstrap_win_dev.vbs bootstrap_win_dev.vbs], then adjust <code>gnucash-on-windows.git/custom.sh</code> to build what you want the way you want, and run
 +
  gnucash-on-windows.sh/install.sh
 +
to build the program.
 +
 
 +
You'll find a shell file, <code>devrc.sh</code> in <code>gnucash-on-windows.git</code>. '''Sourcing''', not running, this file
 +
  . gnucash-on-windows.git/devrc.sh
 +
will set the necessary environment variables so that you can re-run the build script as usual in <code>gnucash/build</code> and run GnuCash from <code>gnucash/inst/bin</code>
 +
[[Category:Building]]
 +
[[Category:Development]]

Latest revision as of 23:58, 5 July 2024

Development on Microsoft Windows isn't really encouraged. The build environment isn't really conducive to development and many of the unit tests don't work. However, if you must...

GnuCash 3.0 and Later

The build system for GnuCash 2.7 and later supports Windows 7 and later. The procedure is a bit simpler than for GnuCash 2.6 and earlier and provides a somewhat easier to use development environment. That doesn't mean that we recommend that you use Windows for development: GnuCash is very much a Unix program and development is much easier in a Unix environment like Linux, BSD, or MacOS.

PowerShell

The build system relies heavily on Windows PowerShell.

Windows 7: The PowerShell version that ships with Windows 7 by default is too old. To build GnuCash on that platform a more recent version of PowerShell should be installed. PowerShell version 5.1 is known to work well.
Depending on your security settings you may need to enable running scripts on your computer. For this open a powershell with Administrator privilages and run:
set-executionpolicy unrestricted

Bootstrap the build environment

First download and run setup-mingw64.ps1. Depending on where you want to put the development tree you may need to run PowerShell as an administrator. Once you've downloaded the script start PowerShell. You can review the script's parameters with
help \path\to\setup-mingw64.ps1
For convenience they're
  • target_dir: The root directory where the build environment will be installed. The default is c:\gcdev64, but you can put it anywhere you have write privilege.
  • download_dir: Defaults to target_dir\downloads. There's no requirement to have it in target_dir.
  • x86_64: Set this to $true if you want to build 64-bit binaries. The default is $false, and the developers do not often try to build 64-bit binaries so doing so isn't guaranteed to work nor are the developers much inclined to prioritize fixing it if it doesn't.
Note: The help command above will only work if the security settings of your system allow this script to be run. In addition to the set-executionpolicy command above you may have to run
unblock-file \path\to\setup-mingw64.ps1
before help will work.

Once setup-mingw64.ps1 is complete you will have an MSYS2 environment with all of the GnuCash dependencies that don't need to be built from source installed in it.

Running a build

Next open the Start menu and navigate to MSYS2 64Bit or MSYS2 32Bit; which you want will depend upon the bitness of your Windows version. If you specified x86_64 $true to setup-mingw64.ps1 you'll want to start the mingw64 shell, otherwise the mingw32 shell.

Note
Currently [2024-07] WebKitGtk is only availabe in 32-bit and won't link with a 64-bit GnuCash.

In that shell window navigate to the gnucash-on-windows.git directory in the target directory to specified to setup-mingw64.ps1. We'll use the default for the following examples.

  cd /c/gcdev64/src/gnucash-on-windows.git
  TARGET=gnucash-unstable jhbuild -f jhbuildrc build

One of the things setup-mingw64.ps1 did was checkout the rest of the gnucash-on-windows repository in target_dir/src/gnucash-on-windows.git. That contains a customization (python) script and a jhbuild moduleset. The customization script selects one of the three GnuCash branches to build based on the value of $TARGET; the possibilities are gnucash-stable (the default), gnucash-unstable (the unstable release git branch) and gnucash-releases, which builds GnuCash from the tarball specified in gnucash.modules instead of from a git branch.The first time jhbuild build command will build GnuCash, GnuCash Docs, and all of the dependencies that Mingw-w64 doesn't provide. After that it only builds modules that need rebuilding unless you tell it otherwise; see the jhbuild manual for details on controlling jhbuild.

You can start a subshell with the paths to hand-compile or run GnuCash from the command line with
TARGET=gnucash-unstable jhbuild -f jhbuildrc shell
This is convenient for development as one can navigate to the gnucash build directory and re-run CMake and make as necessary while developing. N.B. Be sure to use a programming editor that preserves line ending style; git can get really unhappy if you put the wrong kind of line endings into a file. To build a package for installation there's a PowerShell script called gnucash-on-windows.git\bundle-gnucash.ps1 and an automation script, gnucash-on-windows.git\buildserver\build_package.ps1 suitable for use with the Task Scheduler for periodic builds. Each includes documentation accessible with PowerShell's help command, e.g.
help bundle-gnucash.ps1

Note that build_package.ps1 also takes care of updating the gnucash-on-windows repository and that jhbuild build will update the gnucash repository; you can do so manually with git from within the Mingw shell. SSH works, just set up your ~/.ssh directory with the necessary keys and config file.

You may find the MSys2 Wiki and Mingw-w64 Documentation helpful.

Debugging a build

GDB can be used on windows without too much effort. Usually it's better to attach to an already running process instead of trying to launch directly under GDB. Ctrl+C does not work as well under GDB, however this site has a workaround: Workaround for GDB Ctrl C Interrupt

Microsoft's Visual Studio Code is a possibility to integrate with gnucash and gdb for debugging. The following launch.json file can be used to debug with gdb under vscode:

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "(gdb) launch",
            "type": "cppdbg",
            "request": "launch",
            "program": "C:\\gcdev64\\gnucash\\maint\\inst\\bin\\gnucash.exe",
            "args": [],
            "stopAtEntry": true,
            "cwd": "${workspaceFolder}",
            "environment": [],
            "externalConsole": true,
            "MIMode": "gdb",
            "miDebuggerPath": "C:\\gcdev64\\msys2\\mingw32\\bin\\gdb.exe",
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ]
        }
    ]
}

GnuCash 2.6 and Earlier

GnuCash 2.6 is no longer being developed. This procedure is archival. Don't use it without good reason.

First read the README for the Windows Build Environment. You'll need to download and run bootstrap_win_dev.vbs, then adjust gnucash-on-windows.git/custom.sh to build what you want the way you want, and run

 gnucash-on-windows.sh/install.sh

to build the program.

You'll find a shell file, devrc.sh in gnucash-on-windows.git. Sourcing, not running, this file

 . gnucash-on-windows.git/devrc.sh

will set the necessary environment variables so that you can re-run the build script as usual in gnucash/build and run GnuCash from gnucash/inst/bin