Difference between revisions of "Building on Windows"

From GnuCash
Jump to: navigation, search
(GnuCash 3.0 and Later: A note for Windows 7 users and a too old default powershell)
 
(14 intermediate revisions by 5 users not shown)
Line 3: Line 3:
 
= GnuCash 3.0 and Later =
 
= 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 that 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.
+
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.
  
The buildsystem relies heavily on Windows PowerShell. The PowerShell version that ships with Windows 7 however is too old for the GnuCash build system. In order to build GnuCash on that platform the first step to take is to install a newer version of [https://docs.microsoft.com/en-us/dotnet/framework/install/guide-for-developersthe .Net framework] and [https://docs.microsoft.com/en-us/powershell/scripting/install/installing-windows-powershell?view=powershell-6#upgrading-existing-windows-powershell PowerShell]. Version 4.5 of the .Net framework in combination with PowerShell 5.1 is known to work well.
+
== PowerShell ==
  
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. Depending on your security settings you may need to enable running scripts on your computer: <syntaxhighlight lang="powershell">set-executionpolicy unrestricted</syntaxhighlight> 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
+
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 [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.
 +
 
 +
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>
 +
 
 +
== Bootstrap the build environment ==
 +
 
 +
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
 
* 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.
 
* 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.
 
* 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.
+
* 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 <syntaxhighlight lang="powershell">unblock-file \path\to\setup-mingw64.ps1</syntaxhighlight> before help will work.
  
 
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.
 
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.
  
:'''WARNING:''' The Mingw-w64 folks routinely upgrade ICU without also upgrading WebKitGtk3 so that the latter can't resolve its ICU dependency because ICU versions their library names. Add the following to <tt>c:\gcdev64\msys2\etc\pacman.conf</tt>, creating it if necessary, to protect your build environment from breaking this way:
+
== Running a build ==
  IgnorePkg  = mingw-w64-i686-icu
 
  IgnorePkg  = mingw-w64-i686-boost
 
  IgnorePkg  = mingw-w64-i686-harfbuzz
 
  IgnorePkg  = mingw-w64-i686-webkitgtk3
 
Changing <tt>i686</tt> to <tt>x86_64</tt> if appropriate. For a new build environment '''do this BEFORE running any of the powershell scripts or pacman -Su!'''
 
 
 
When setting up a new build environment or if you get an upgrade that breaks the build, you can recover as follows:
 
* Visit [http://repo.msys2.org/mingw/ MSYS2's download site], select the <tt>i686</tt> or <tt>x86_64</tt> directory, and find the latest tarball for webkitgtk3. Note its date.
 
* Find the ICU tarballs and note the dates of the tarballs before and after the webkitgtk3 date.
 
* Download the earlier ICU tarball.
 
* Download the Boost and Harfbuzz tarballs whose dates are between the two ICU dates.
 
* Install each tarball with <tt>pacman -U</tt>, e.g.:
 
  pacman -U /path/to/mingw-w64-i686-icu-61.1-1-any.pkg.tar.xz
 
  
 
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.
 
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.
Line 35: Line 32:
 
   TARGET=gnucash-unstable jhbuild -f jhbuildrc build
 
   TARGET=gnucash-unstable jhbuild -f jhbuildrc build
 
</syntaxhighlight>
 
</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-master</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. When we release GnuCash 2.8.0 <tt>gnucash-unstable</tt> will be replaced with <tt>gnucash-maint</tt>. 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.
+
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.
  
 
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.
 
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.
  
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>.
+
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>
  
 
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.
 
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.
 
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 and Earlier =
Line 56: Line 85:
 
   . gnucash-on-windows.git/devrc.sh
 
   . 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>
 
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 21:16, 31 March 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. 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