Skip to content

Instantly share code, notes, and snippets.

@ngleb
Last active November 2, 2021 02:41
Show Gist options
  • Save ngleb/944346a67960776371aab74149edf38c to your computer and use it in GitHub Desktop.
Save ngleb/944346a67960776371aab74149edf38c to your computer and use it in GitHub Desktop.
How to build ledger under Windows using MSYS2/MinGW

Install MSYS2

Manual is on the home page http://www.msys2.org/

Run MINGW32 (32 bit environment) and update it

pacman --needed -Syu

Install dependencies

Update everything, install toolchain and dependencies (probably something is missing):

pacman --needed -S base-devel git \
                   mingw-w64-i686-toolchain \
                   mingw-w64-i686-cmake \
                   mingw-w64-i686-boost \
                   mingw-w64-i686-mpfr

Clone ledger tree

Git clone ledger tree (master branch):

git clone https://github.com/ledger/ledger.git ledger

Build ledger

cd ledger
cmake -G 'MSYS Makefiles'
make

If everything went well, ledger.exe will appear in the same dir. It can be checked by running it:

./ledger

Copy ledger

Now ledger and its dependencies can be copied to somewhere for using it outside of MSYS2 environment, for example, /c/ledger. ledger then can be used as a normal Windows application, from CMD or from GNU Emacs with ledger-mode (path expantion will work properly). In this case it's useful to add C:\ledger to PATH environment variable.

mkdir /c/ledger
cp ./ledger.exe /c/ledger
cp ./libledger.dll /c/ledger
cp /mingw32/bin/libboost_filesystem-mt.dll /c/ledger
cp /mingw32/bin/libboost_regex-mt.dll /c/ledger
cp /mingw32/bin/libboost_system-mt.dll /c/ledger
cp /mingw32/bin/libgcc_s_dw2-1.dll /c/ledger
cp /mingw32/bin/libgmp-10.dll /c/ledger
cp /mingw32/bin/libicudt64.dll /c/ledger
cp /mingw32/bin/libicuuc64.dll /c/ledger
cp /mingw32/bin/libstdc++-6.dll /c/ledger
cp /mingw32/bin/libwinpthread-1.dll /c/ledger

Some packages may be updated at some point, so the name of files might change as well (e.g. icu libs will have 59 instead of 58).

@ngleb
Copy link
Author

ngleb commented Sep 29, 2017

@chrisleaman
Hi! Thanks for the info, I've updated dll versions.

@brownstyler
Copy link

This worked for me as well! Thank you!

@yiufung
Copy link

yiufung commented May 2, 2018

What a gem, works perfectly, thank you! Btw, the dll versions for libicudt and libicuuc have bumped to 61 already. Maybe put it as comment (#) at the end of cp line? That should be more eye-catching for desperate Windows-befuddled copy-pasters :P

@Arjay-El
Copy link

I recompiled per the instructions and it fixed the paths being called from a cmd window.

However if I call a file from an org-babel block in emacs like this:

#+begin_src ledger :cmdline bal :results output :exports results
!include "d:/Ledger/budget.ledger"
#+end_src

the path to the data file is interpreted as this "c:/Users\Arjay\AppData\Local\Temp\babel-16324iS0&"d:/Ledger\budget.ledger&" and is not found. Any ideas what may cause this seeing as it works fine form the cmd line?

@ngleb
Copy link
Author

ngleb commented Jul 28, 2018

@Arjay-El

Any ideas what may cause this seeing as it works fine form the cmd line?

I've checked your case and I could reproduce the issue. You can resolve it this way (see the cmdline):

#+begin_src ledger :cmdline -f d:/Ledger/budget.ledger bal :results output :exports results
#+end_src

Also, the issue is not related to org-babel, the problem is with ledger and you can reproduce it if you use absolute windows paths in !include. You can check it this way. Let's say you have:
d:/Ledger/budget.ledger
Add another file:
d:/Ledger/test.ledger and add the following line to this file:
!include "d:/Ledger/budget.ledger"

If you run this command from d:/Ledger, then this same issue will happen.

@lanrete
Copy link

lanrete commented Nov 3, 2018

Thank you for this! Pretty helpful and I finally resolve the path issue when using abspath from command line. Works like a charm.

However I do run into some issues where the color are not showing up correctly in cmd or powershell (however they are showing up correctly in emacs though) I get something like this when running a single bal command

�[31mXXX -XX.XX�[0m �[34mIncome:Invest:Saving�[0m

Have you met such situation? Do you have any kind suggestion on this?

@ngleb
Copy link
Author

ngleb commented Dec 13, 2018

@lanrete

Have you met such situation? Do you have any kind suggestion on this?

I don't think Windows supports this well, not before Windows 10 according to this. I use ConEmu with Far Manager, it works much better than regular cmd.exe.

@LewWadoo
Copy link

There is no 'MSYS Makefiles' generator on my platform MSYS2 on Windows 10:

The following generators are available on this platform (* marks default):

  • Unix Makefiles = Generates standard UNIX makefiles.
    Ninja = Generates build.ninja files.
    CodeBlocks - Ninja = Generates CodeBlocks project files.
    CodeBlocks - Unix Makefiles = Generates CodeBlocks project files.
    CodeLite - Ninja = Generates CodeLite project files.
    CodeLite - Unix Makefiles = Generates CodeLite project files.
    Sublime Text 2 - Ninja = Generates Sublime Text 2 project files.
    Sublime Text 2 - Unix Makefiles
    = Generates Sublime Text 2 project files.
    Kate - Ninja = Generates Kate project files.
    Kate - Unix Makefiles = Generates Kate project files.
    Eclipse CDT4 - Ninja = Generates Eclipse CDT 4.0 project files.
    Eclipse CDT4 - Unix Makefiles= Generates Eclipse CDT 4.0 project files.

@ngleb
Copy link
Author

ngleb commented Oct 19, 2019

There is no 'MSYS Makefiles' generator on my platform MSYS2 on Windows 10:

What shell do you start on Windows (msys or mingw)?

@ngleb
Copy link
Author

ngleb commented Oct 19, 2019

I couldn't reproduce your issue. Make sure that you start MSYS2 MinGW 32-bit, not MSYS2 MSYS.

@LewWadoo
Copy link

There is no 'MSYS Makefiles' generator on my platform MSYS2 on Windows 10:

What shell do you start on Windows (msys or mingw)?

C:\msys64\msys2_shell.cmd -msys

@ngleb
Copy link
Author

ngleb commented Oct 21, 2019

There is no 'MSYS Makefiles' generator on my platform MSYS2 on Windows 10:

What shell do you start on Windows (msys or mingw)?

C:\msys64\msys2_shell.cmd -msys

As I have mentioned earlier, MSYS shell will not work for this guide. You need to use MinGW32 shell which will build native Windows binary of ledger which will work outside of MSYS environment.

I think the correct command in your case would be:
C:\msys64\msys2_shell.cmd -mingw32

@LewWadoo
Copy link

There is no 'MSYS Makefiles' generator on my platform MSYS2 on Windows 10:

What shell do you start on Windows (msys or mingw)?

C:\msys64\msys2_shell.cmd -msys

As I have mentioned earlier, MSYS shell will not work for this guide. You need to use MinGW32 shell which will build native Windows binary of ledger which will work outside of MSYS environment.

I think the correct command in your case would be:
C:\msys64\msys2_shell.cmd -mingw32

Now the issue has gone! Thank you!

@Eason0210
Copy link

Is it possible to build ledger with Mingw64 on Msys2?

@ngleb
Copy link
Author

ngleb commented Feb 1, 2021

Is it possible to build ledger with Mingw64 on Msys2?

I don't think so. I tried it, but it didn't work. Here's my report at ledger/ledger#1905

There's pull request attached to this issue, so it might be fixed soon.

@mundifex
Copy link

mundifex commented Nov 2, 2021

Thank you so much for this! The binaries available at https://github.com/FullofQuarks/Windows-Ledger-Binaries/ were segfaulting for me when sorting balance reports. Built my own binaries according to your instructions and am encountering no errors.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment