Pages

Saturday, October 6, 2012

Build LibreOffice on OS X 10.8 with Xcode 4.5

A lot of people have problems with building LibreOffice on OS X Mountain Lion with latest Xcode 4.5.
Below you can see how I succeeded with it.

I tried building LibreOffice 3.6.1.2.
At first I tell you what you should NOT do to build LibreOffice.
Then you will see steps to build LibreOffice 3.6.1.2 on OS X 10.8 with Xcode 4.5.


What you should NOT do to build LibreOffice

Do not try to build LibreOffice from source codes archive file.

My first try was building source codes from file libreoffice-core-3.6.1.2.tar.xz. This archive contains dozens of files that renamed to names with "_" (underscore) sign at the end of file name.
This leads to build errors like this one:
javac: file not found: /Users/fsv/projects/libreoffice-core-3.6.1.2/jurt/com/sun/star/lib/uno/bridges/java_remote/XConnectionInputStream_Adapter.java
This is because file XConnectionInputStream_Adapter.java renamed to XConnectionInputStream_Adapter.java_.

Do not try to build LibreOffice with MacOSX SDK 10.7 or MacOSX SDK 10.8.

You need MacOSX SDK 10.6. One of the reasons is QuickTime.framework with deprecated function KillPicture. This function is not declared in headers of SDK 10.7 and 10.8. Only in SDK 10.6.
If you'll use SDK 10.7, you'll see next build error:
/Users/fsv/projects/libreoffice-core/vcl/aqua/source/dtrans/PictToBmpFlt.cxx:133:7: error: use of undeclared identifier 'KillPicture'
Xcode 4.5 doesn't have MacOSX SDK 10.6. You will see next error if you add --with-macosx-version-min-required=10.6 parameter:
checking the presence of the SDK 10.6... configure: error: /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.6.sdk not found
Below I tell how to add SDK 10.6 to Xcode 4.5.

Do not try to build LibreOffice with gcc/g++

There were a lot of build errors that I couldn't solve. For example this one:
Undefined symbols for architecture i386:  "com::sun::star::uno::Reference<com::sun::star::uno::XInterface>::operator com::sun::star::uno::Reference<com::sun::star::uno::XInterface> const&() const", referenced from:      non-virtual thunk to ucbhelper::ContentImplHelper::getParent()in contenthelper.old: symbol(s) not found for architecture i386
Instead of gcc/g++ use clang/clang++.

Do not try to build LibreOffice for x86_64 architecture

This will lead to build errors like this one:
macosx-create-bundle: error: file is not an executable or shared library.
You need add -m32 parameter to CC/CXX

Do not try to build LibreOffice with --enable-werror parameter

Currently LibreOffice have a lot of warnings unfixed. --enable-werror option adds -Werror parameter to compiler, and unused parameters/variables will generate build errors like this one:
/Users/fsv/projects/libreoffice-core/cppu/source/uno/lbenv.cxx:199:50: error: unused variable 'insertion' [-Werror,-Wunused-variable]
    ::std::pair< Ptr2ObjectMap::iterator, bool > insertion(

Do not try re-run `./autogen.sh` with different options without `make clean`

This can lead to build errors. And it's hard to find what's happened.
If you want to change some options for autogen.sh script, always run `make clean`.



Steps To build LibreOffice on Mac OS X 10.8 with Xcode 4.5

Now it's time to list all steps to build LibreOffice

Step 1. Add MacOSXSDK10.6 to Xcode

Xcode 4.5 doesn't have OS X SDK 10.6.
But you can download Xcode 4.3.2 for Lion here. Mount dmg image and copy SDK:
`sudo cp -r /Volumes/Xcode/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.6.sdk /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.6.sdk`

Step 2. Install Xcode Command Line Tools

In Xcode 4.5 go Xcode -> Preferences... -> Downloads -> Components, then choose install Command Line Tools

Step 3. Install MacPorts, install autotools and other tools

Install MacPorts.
Then run next command:
`sudo port install autoconf automake m4 p5-archive-zip`

Step 4. Clone LibreOffice git repository, checkout branch that you need

`git clone git://anongit.freedesktop.org/libreoffice/core libreoffice-core`
Then checkout branch that you need. For me this is
`git checkout libreoffice-3-6-1`

Step 5. Run autogen.sh and make

Create autogen.lastrun file in source codes root directory with next content:
--disable-binfilter
--disable-build-mozilla
--disable-mozilla
--disable-odk
--disable-online-update
--disable-python
--enable-debug=cppu/ cppuhelper/ sal/ sfx2/ stoc/ sw/ toolkit/ unotools/ vcl/
--enable-epm
--with-java-target-version=1.6
--with-macosx-version-min-required=10.6
--with-max-jobs=2
--with-num-cpus=2
--without-doxygen
--without-help
--without-helppack-integration
--without-myspell-dicts
CC=clang -m32
CXX=clang++ -m32
You can add/change/remove some params, but do NOT try adding --enable-werror param!
Then run autogen.sh script without args. It will use parameters from autogen.lastrun file.

Then you can make LibreOffice:
`make`

Build succeeded in 1.5 hours.

No comments:

Post a Comment