Building LibreOffice on Windows with Cygwin and MSVC: Tips and Tricks

From The Document Foundation Wiki
Jump to: navigation, search

Build dependencies

Before you can start hacking LibreOffice on Windows, you need to follow these instructions to set up a build environment.

Im-jabber.svg

Note:
The Easiest way to do that is to use LODE , which automates all that is necessary, beyond installing Visual Studio and Java.
If you want to do it the hard way... keep reading...


Install Cygwin Requirements

On Windows, you must first install Cygwin from www.cygwin.com.

The easiest way to do so is to download Cygwin's setup-x86.exe (32-bit) or setup-x86_64.exe (64-bit).

  • Under Windows 10 x64 version 1511, if you install Cygwin 64-bit, you need Cygwin 2.4.0-0.9 or later (see Cygwin mailing list for details).

This instruction uses the 32-bit version as an example: Run cmd and navigate to the download dir (if you have trouble navigating, you can also drag setup-x86.exe from the file explorer into the cmd window) and copy and paste the command below to run setup-x86.exe with the list of required packages preselected.

  setup-x86.exe -P autoconf -P automake -P bison -P cabextract -P doxygen -P flex -P gcc-g++ ^
                -P git -P gnupg -P gperf -P make -P mintty ^
                -P nasm -P openssh -P openssl -P patch -P perl -P python -P python3 ^
                -P pkg-config -P rsync -P unzip -P vim -P wget -P zip -P perl_vendor 

With setup-x86_64.exe, we need to replace perl_vendor with perl-Archive-Zip, giving this command line:

  setup-x86_64.exe -P autoconf -P automake -P bison -P cabextract -P doxygen -P flex -P gcc-g++ ^
                -P git -P gnupg -P gperf -P make -P mintty ^
                -P nasm -P openssh -P openssl -P patch -P perl -P python -P python3 ^
                -P pkg-config -P rsync -P unzip -P vim -P wget -P zip -P perl-Archive-Zip

This launches the GUI and requires you to manually choose installation paths etc, but the packages passed via command line are pre-selected meaning you just need to accept the selection.

NOTE: installation path of Cygwin mustn't contain non-ASCII letters to avoid autogen.sh/configure problems (if it contains, move folder of the Cygwin installation to a new place and update its Windows shortcuts & Start Menu items).

Alternatively, run the setup-x86.exe or setup-x86_64.exe utility, switch the package view mode to 'Full' by pressing 'View' until 'Full' is displayed beside it, then manually select the packages listed in the above command for installation.

If you upgraded Cygwin, you might have to run the rebaseall command (not needed if you installed Cygwin for the first time):
Close all Cygwin consoles, run c:\cygwin\bin\dash.exe, and in the terminal, launch /bin/rebaseall.

Install Windows Build Requirements

No matter what version of Visual Studio you're using, you need a

  • Java Development Kit (JDK). Make sure to get a 32-bit SDK if you are building for 32-bit Windows, and a 64-bit SDK if you are building for 64-bit Windows (with --enable-64-bit). Grab it from http://www.oracle.com/technetwork/java/javase/downloads/index.html. Note that building for 64-bit is still experimental and you can expect build issues. If you are building for the first time, choose the 32-bit SDK and build for 32-bit.

You also need the Microsoft compiler/development suite Visual Studio, which can be obtained from here: http://www.visualstudio.com/en-us/downloads

Note there are 2 different editions that are free of charge:

LibreOffice 4.4 requires at least Visual Studio 2012, whereas LibreOffice 5.0 requires at least Visual Studio 2013.

When using Visual Studio 2013

Visual Studio 2013 comes with the Windows SDK and DirectX SDK and .NET stuff included. Install Visual Studio 2013 and you have all you need.

If you want your builds to run on Windows XP, you need to use --with-windows-sdk=7.1A

Visual Studio 2015

LO is up and running with new compiler. See this page for more details:

Instructions

Install dependencies, open cygwin command line, and perform next steps:

Install GNU make

A Win32 build of GNU make 4.0+ is made available (and required) for building LibreOffice.

It's easiest to put it in /opt/lo/bin, where configure will automatically find it; you can also use another location and set the MAKE variable. Either prepend /opt/lo/bin to PATH, or alternatively, when you build LibreOffice, always call "make" with the absolute path /opt/lo/bin/make (or wherever you put it). LibreOffice cannot and should not use Cygwin's /usr/bin/make.

  mkdir -p /opt/lo/bin
  
  cd /opt/lo/bin
  wget http://dev-www.libreoffice.org/bin/cygwin/make-85047eb-msvc.exe
  mv make-85047eb-msvc.exe make
  chmod a+x make

Install ant and junit

You can extract them anywhere, they don't have to be installed. If you don't want to use Junit, it can be disabled with --without-junit in the autogen.sh command later.

  mkdir -p /cygdrive/c/sources
  cd /cygdrive/c/sources
  wget https://archive.apache.org/dist/ant/binaries/apache-ant-1.9.5-bin.tar.bz2
  tar -xjvf apache-ant-1.9.5-bin.tar.bz2
  wget http://downloads.sourceforge.net/project/junit/junit/4.10/junit-4.10.jar

Clone the LibreOffice source code repositories

NOTE: sources should be in a relatively short path to avoid exceeding the file/pathname limit and the destination path cannot have any space in it.

  cd /cygdrive/c/sources
  git clone git://gerrit.libreoffice.org/core libo-core

Create build directory and configure and build the code

You can build LibreOffice into another directory than your checkout. This helps keeping the source code tree clean and eases building multiple versions, however it does stop the Visual Studio IDE Integration from working.

If you want to build into a separate directory, say /cygdrive/c/build, enter these commands:

  mkdir /cygdrive/c/build
  cd /cygdrive/c/build

Otherwise change directory to the /cygdrive/c/sources/libo-core folder:

  cd /cygdrive/c/sources/libo-core

Now run autogen.sh to configure the build:

  /cygdrive/c/sources/libo-core/autogen.sh \
               --with-external-tar=/cygdrive/c/sources/lo-externalsrc \
               --with-junit=/cygdrive/c/sources/junit-4.10.jar \
               --with-ant-home=/cygdrive/c/sources/apache-ant-1.9.5 \
               --enable-pch --disable-ccache \
               --disable-activex --disable-atl \
               [additional switches, if you know what you are doing :-) ...]

Note that it's not recommended to use ccache on Windows. If you have it installed in your Cygwin environment, be safe and disable it with --disable-ccache (as in the command above).

If the autogen.sh script complains that it cannot find some header files, it is possible that it cannot locate the your Windows SDK or that it finds a corrupted one. This may happen if you installed multiple version of Visual Studio on your computer, especially if you installed a Beta version, and even if you uninstalled those. In this case, you may use the --with-windows-sdk=7.1A, possibly replacing 7.1A with another version of the SDK to select a specific uncorrupted version.

autogen.sh saves your last used configure switches in a file called autogen.lastrun, so in case you want to run configure with the same parameters again, it is enough to just run autogen.sh without any parameters.

Save a copy of the last used parameters in the file autogen.input:

  mv autogen.lastrun autogen.input

As opposed to autogen.lastrun, autogen.input will not be overridden by autogen.sh when using other parameters. If autogen.sh is called again without parameters, it will fetch its input from autogen.input if it is present.

Read the summary output from the autogen.sh command. If it did not report any errors or relevant warnings, then all that is left to do is to run the right version of make to build LibreOffice:

   /opt/lo/bin/make gb_COLOR=1  # gb_COLOR=1 enables colored output

If the build process fails at this point with the error error C3861: 'InetPtonW': identifier not found, this is because of a bug in the build process for Windows SDK 8. You may work around this by using the --with-windows-sdk=7.1A option.

Run LibreOffice

When the build has finished without errors, you can run your fresh build of LibreOffice using

   instdir/program/soffice.exe

Microsoft Visual Studio Project Integration

The LibreOffice build system can generate project file for some IDEs including -- thanks to Honza Havlíček's excellent work -- Microsoft Visual Studio: (note that this does not allow a full build so you still need to use Cygwin to do full builds)

Build a project file for Visual Studio

The IDE integration script is written in python3, which is not installed by default (using the lode method), please install it in cygwin before running the make command. After a complete build of LibreOffice was successful, execute the following command to generate a Visual Studio project for Visual Studio 2013:

  $ ../../opt/bin/make vs2013-ide-integration


If the generation is successful, the resulting solution file LibreOffice.sln will be placed in the root directory of the build and can be opened with Microsoft Visual Studio.

In order for the solution file to open correctly in Visual Studio, the LibreOffice build must be done to the same directory as the source code; separating the source and build directories stops the IDE integration from working.

Why MSVC?

It is a frequently asked question, usually coming from free software purists, why we use proprietary compiler instead of a free one (i.e. gcc).

  • ABI backwards-compatibility for compiled extensions. There is some resistance to breaking that.
  • So far MSVC produces faster, smaller binaries.
  • There are some features in the code that don't compile with MinGW. They use API that MinGW does not provide headers for etc.
  • There are open questions around how we would run unit tests in a MinGW cross-compilation environment.
  • There are open questions around how well gdb works on Windows; the MSVC C++ debugger is really quite good.

Autogen options

Something like the following in the autogen.input file is known to produce a working build:

--disable-odk
--with-junit=/cygdrive/c/sources/junit-4.10.jar
--with-ant-home=/cygdrive/c/sources/apache-ant-1.9.5
--enable-pch
--disable-ccache

Of course, change the information behind ='s to fit your needs; set the paths to what you have used when installing various prerequisites.

You also need to specify the path for ant with --with-ant-home=<cygwin path of ant>.

If you use the gratis Visual Studio Express, then use --disable-activex and --disable-atl, because only the full version of Visual Studio contains the required headers for ActiveX and ATL support.

Remember to restart the shell after you install Microsoft tools, before you run autogen.

64-bit Visual Studio build

A port for 64-bit Windows is working on master: to build it use the --enable-64-bit flag for configure.

Visual Studio 2012 compiler

Visual Studio 2012 is currently used for 4.4 release builds, but master requires 2013.

Visual Studio 2013 compiler

Visual Studio 2013 is known to work on current master and on all tinderboxes.

Visual Studio 2015 compiler

Visual Studio 2015 is known to work on current master, both 64bit (--enable-64-bit) and 32bit modes. One exception: --disable-firebird-sdbc. See this upstream issue for more details: [1].

Switching to non default compiler

Specify which Visual Studio version to use in case several are installed.

If not specified, the order of preference is 2013, 2015.

--with-visual-studio=2015

ATL and ActiveX

There is a "Visual Studio Community 2013" that can be used free of charge to contribute to open source projects, and it includes the ATL and ActiveX headers (so you should install it instead of the "Express" editions).

Visual Studio Express: Disable ATL

If you use a Visual Studio Express, the file atlbase.h is missing. Use the parameter --disable-atl, otherwise the build breaks in embedserv. Use the parameter --disable-activex in addition, if it still breaks in extensions\source\activex\.

Getting ATL to work with Visual Studio Express

ATL is used for OLE-objects of foreign applications, for example for to use Math Type formulas. Thanks to a hint by Mathias Bauer [1] I was able to build LibreOffice with enabled atl.

  • Download the "Windows Driver Kit Version 7.1.0" (Link visited 2011-11-13)
  • Burn the file to CD and then install the software. With default settings you get a folder C:\WinDDK.

There is currently (November 2011) no parameter to tell configure the paths to the ATL folders. You will need to enter the path manually. Follow the steps below.

  • Run autogen.sh without using the switch --disable-atl. Do not continue building immediately.
  • Open the file Config_host.mk in the source root directory in an editor. Search for the lines beginning with ATL_LIB, ATL_INCLUDE, MFC_LIB, and MFC_INCLUDE.
  • Change the paths to those of the WinDDK directory as shown below.
 
ATL_LIB="C:/WinDDK/7600.16385.1/lib/ATL/i386"
ATL_INCLUDE="C:/WinDDK/7600.16385.1/inc/atl71"
MFC_LIB="C:/WinDDK/7600.16385.1/lib/Mfc/i386"
MFC_INCLUDE="C:/WinDDK/7600.16385.1/inc/mfc42"
  • Continue building with make.

Note that using --disable-activex without --disable-atl makes autogen to presume that ATL headers and libs are located in SDK subdirectories, and not in VC subdirectories. This may cause errors if full-featured Visual Studio SKU is used (like Community edition). In that case, you will either need to manually fix Config_host.mk, or avoid using --disable-activex.

Known Problems

Cygwin Shell

You will use Cygwin Bash Shell for the whole build process. You must install all the build dependencies above before starting the shell to run autogen because autogen needs some environment variables to find the tools.

If you see an error similar to the following when running autogen.sh

   $'\r': command not found

This means that that windows style newline characters are creating issues with the Cygwin Shell. A way to solve this is to create the windows environment variable SHELLOPTS with the value:

   (set -o igncr) 2>/dev/null && set -o igncr;

Big List Of Dodgy Apps

If you get mysterious build breaks, building is very slow or your systems hangs totally, check if you are running an application which interferes with Cygwin. For a list of known offenders, see this point in the Cygwin FAQ.

Buildability of 'master'

If you are building the Windows build for the first time, it is recommended that you check the current state of http://tinderbox.libreoffice.org/MASTER/status.html . If you see recent "green" builds, it is a good time to try - otherwise it might happen to you that you'll have to fix the build yourself. The buildability on Windows has improved recently with the introduction of the MinGW and more stable native Windows tinderboxes, but still there might be a day or two when 'master' is not buildable on Windows.

The usual recommendation is to just pull and try again, and once you have a build, don't pull in the tree any more, but do your hacking in it. Clone a different tree and iterate pulling and building in that until it again works, then switch. Repeat.

Alternatively, if you find a known good state (a green box) for Windows on the Tinderbox side back in history, you can do:

git checkout -b my_workbranchname ${last_good_commit}

to start working on a branch starting at the last good state.

BitDefender / other Anti-Virus / security tools breaking the build

If your build fails with a FileNotFoundError: such as The system cannot find the file specified: '../../../dist/out/bin\\example.exe', there's a good chance your Anti-Virus is quarantining or deleting important files.

Another potential source of problems are the sample documents (those labeled CVE) that check for known vulnerabilities to ensure they don't reappear again. In the source they are stored encrypted to avoid triggering the warnings, but when the corresponding test is run, the original is created in the temp directory and tools such as BitDefender can flag it.

If you want to run these tests, disable monitoring of the temporary build-directories <root of repo>\*\pass and C:\cygwin\tmp in your Anti-Virus tool. For Windows 8.1 you will need to disable Windows Defender launch - search for and launch 'defender' from the shell.

You can also use the --disable-cve-tests autogen flag to skip the tests that are known to cause trouble.

Also note that Anti-Virus tools can slow down your build quite a bit, if you want to build fast you should disable real time monitoring of the source tree and the temporary files directory C:\cygwin\tmp.

Norton Antivirus breaking the build

Norton Antivirus and Symantec Endpoint Protection complain about certain files that the build produces. It finds the following files (in a build without "--enable-dbgutil" )

Malware: Suspicious.Cloud
D:\bld\rel\workdir\UnpackedTarball\icu\source\bin\genrb.exe*
Malware: Suspicious.Cloud.5
D:\bld\rel\workdir\UnpackedTarball\nss\nss\lib\zlib\out\example.exe*
D:\bld\rel\workdir\UnpackedTarball\nss\dist\out\bin\example.exe* 
D:\bld\rel\instdir\program\reg4allmsdoc.dll
D:\bld\rel\instdir\program\sdqsmsi.dll
D:\bld\rel\instdir\program\sellangmsi.dll

Files with * are needed for the build - exclude them from the virus scan!

The following files appear with varying names (????) in a release build, so you cannot exclude them from the scan.

D:\bld\rel\instdir\program\RCX????.tmp
D:\bld\rel\instdir\program\RCX????.tmp
D:\bld\rel\instdir\program\RCX????.tmp

Current workaround: Don't do release builds (unless you are allowed/willing to switch off the virus scanner).

System PATH causing weird build breakage

The build imports the system PATH for DLL lookups. If you experience weird build breakage that no one else seems to experience, check your PATH value and try cleaning it. Note that you need to re-run configure in order for the new system PATH value to take effect in your build. For example, the author has experienced a build failure in the shell module due to his system PATH including a path to an older OOo installation which had a DLL of the same name as the one that the build uses.

Windows Update automatically reboot during compilation

Sometimes Microsoft Windows reboot during compilation. It happen because Windows Update updates operating system and reboot. To stop windows update from command line, you can enter following command in command box;

C:> net stop wuauserv

It stops a Windows Update service process.

Other known problems

  • Paths that include /opt cause problems with some external modules; it is best to avoid having your source tree in /opt; or use --disable-orcus to overcome this.
  • Asian locale builds sometimes fail due to encoding issues in the source code; in these cases, patches to fix those problems are appreciated. Alternatively, configure Windows for a US locale.


Building older release branches

While master and libreoffice-4-5 and later release branches require Visual Studio 2013, you can build older release branches with older Visual Studio versions too.

Installing Visual Studio 2012

Only for LibreOffice versions newer than 4.0:

Visual Studio 2012 comes with the Windows SDK and DirectX SDK and .NET stuff included. Install Visual Studio 2012 and you have all you need.

If you want your builds to run on Windows XP, you need to install VS 2012 update 1 (or later, current as of this writing is update 3) and use --with-windows-sdk=7.1A

Installing Visual Studio 2010

As Visual Studio 2010 doesn't come with all necessary files included, you need to install some additional packages.

Optional packages

If you want to build mozilla from source (doesn't apply to master/current codeline), you need the

Install GNU make

Warning: The native Win32 GNU make only works to build the master branch leading up to the 4.4 release; for building release branches for 4.3 and earlier, you need a Cygwin GNU make from here.

Visual Studio 2010 compiler

Note: It is not possible to build current LibreOffice with Visual Studio 2010; the last release branch that builds with 2010 is libreoffice-4-3 for the 4.3.x releases.

As of 31.10.2012 it is working on Windows Server 2008 64 bit (current master). If you get this configuration error "checking string.h... no" string not found, that's mean that you don't have any C-HEADER in your <install_visual_studio_dir>\VC\include directory. To resolve, you have to reinstal VS 2010 and check your registry as it says here: http://stackoverflow.com/questions/12460307/installation-of-visual-studio-2010-any-edition-installs-only-2-files-in-the-c and here http://connect.microsoft.com/VisualStudio/feedback/details/774158/re-installed-visual-studio-2010-and-c-standard-headers-are-missing

Visual Studio 2008 compiler

Note: It is not possible to build current LibreOffice with Visual Studio 2008; the last release branch that builds with 2008 is libreoffice-4-0 for the 4.0.x releases.

If you use Windows SDK 7+ with VS2008 Express, you should register it after install. You should do it with Start>Programs>Microsoft Windows SDK v7.1>Visual Studio Registration>Windows SDK Configuration Tool. If this does not work, open the SDK console (one step up), and execute: WindowsSdkVer.exe -version:v7.1 -legacy (Thanks to Chromium build instructions).

Optional requirements to build Mozilla Address Book connector

Building the bundled mozilla from source is not possible currently. When you want to use precompiled mozilla, for example because you want to enable the old mozilla addressbook connector (with --enable-win-mozab-driver), you need the Visual C++ 2005 runtimes in the external-tarball folder.

Perhaps you find these files already on your PC, because another application has installed them. Look into a subfolder of Windows\winsxs which name starts with x86_Microsoft.VC80.CRT_1fc8b3b9a1e18e3b.

Another way is to use the 'Microsoft Visual C++ 2005 SP1 Redistributable Package (x86)', last seen at this location. Unfortunately it does not deliver the file MICROSOFT.VC80.CRT.manifest. But this is a pure text file and you can write it using your editor. Use DOS line ends and UTF-8. For me the following content works, although it might not be "correct". I took the version number from the files. Put all those files into external\tarballs. (This location provides latest VC++ runtimes, including 2005, and the version of vcredist 2005 indicated there seems to contain proper manifest.)

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
    <noInheritable/>
    <assemblyIdentity 
        type="win32" 
        name="Microsoft.VC80.CRT" 
        version="8.00.50727.6195" 
        processorArchitecture="x86" 
        publicKeyToken="1fc8b3b9a1e18e3b"
    />
    <file name="msvcr80.dll"/>
    <file name="msvcp80.dll"/>
    <file name="msvcm80.dll"/>
</assembly>

See also