Install and configure the SDK for building LibreOffice extension

Introduction

During the development of our DSS product, it was required to create an extension for LibreOffice in C ++. The choice of language was due to the presence of existing projects in C ++, but I did not want to create a “zoo” in the projects.
Started to study materials on this issue, articles, including on this resource. It would seem that there is quite a lot of data, but in fact the information was either very scarce, or it was no longer relevant due to outdated versions of LO.
I had to study the issue on my own.
image

SDK assembly

To build under Windows you will need:

  • LibreOffice 6.2.4 / 6.2.5 + LibreOffice SDK 6.2.4 / 6.2.5 ( Libreoffice & SDK) or version higher.
  • GNU Zip Make CoreUtils Sed ( GNU )
  • jdk (Jdk)
  • Microsoft VS with installed compiler for C ++ + MSTools and Microsoft.NET

The main steps:

Install LibreOffice and LibreOffice SDK, preferably in the “Without spaces” directory.
Example C: App Libreoffice6.2.4.2×64 and C: App Libreoffice6.2.4.2×64 sdk, respectively.
Open the console, go to the directory containing our downloaded SDK:
cd C: App Libreoffice6.2.4.2×64 sdk
Run setsdkenv_windows.bat
This script, at the first start, generates a batch file for your user in the system, in which it suggests registering the paths to:

  1. LibreOffice
  2. LibreOffice SDK;
  3. GNU utilities for building packages, C ++, C # and VB.NET compilers, and the Java SDK directory.

Specify the appropriate folders.

Important! You must specify all the paths to the versions of the corresponding bit depths. “Automatic deployment of UNO components (YES / NO)” will install the package immediately after assembly, I chose NO. It is also necessary to go along the path to the batch file, for example C: Users yurev.admin AppData Roaming libreoffice6.2_sdk and adjust the path to VCVARS32 using handles, I did this through a new variable.

set OO_SDK_CPP_HOME=C:Program Files (x86)Microsoft Visual Studio2019EnterpriseVCToolsMSVC14.20.27508binHostX64x64
set OO_SDK_VCVARS_HOME=C:Program Files (x86)Microsoft Visual Studio2019EnterpriseVCAuxiliaryBuild
if defined OO_SDK_VCVARS_HOME call "%OO_SDK_VCVARS_HOME%VCVARS64.bat" 

You need to choose a path for your bit depth.

After successfully setting the environment variables, we will receive the following message:
image

There should not be any comments – this will affect the assembly later. The command line goes into Shell prepared for SDK mode.

Also, go to the directory with the GNU packages (C: Program Files (x86) GnuWin32 bin) and rename the link.exe linker,
so that in the future he would not get confused with the Microsoft linker, if necessary, we can always call him by his new name.

SDK compilation

The next step is to compile the headers or (for Java) classes. By itself, the SDK is a set of components with the extension .idl,
which are collected in .udl blocks, which, in turn, are collected in the registry with the extension .rdb.
In this form, of course, it is impossible to use it, the goal of this approach is the ability to write your own components,
which are then added to the shared tree.

Take the project from the LibreOffice example.
Go to the C: App Libreoffice6.2.4.2×64 sdk examples cpp complextoolbarcontrols directory and execute make.
If the data in the first step is entered correctly and the environment variables are set correctly, then we will see

C:AppLibreoffice6.2.4.2x64sdkexamplescppcomplextoolbarcontrols>make
mkdir c:libreoffice6.2_sdkWINexample.outslocomplextoolbarcontrols
Подпапка или файл c:libreoffice6.2_sdkWINexample.outslocomplextoolbarcontrols уже существует.
make: [c:/libreoffice6.2_sdk/WINexample.out/slo/complextoolbarcontrols/MyProtocolHandler.obj] Ошибка 1 (игнорирована)
cl -c -MD -Zm500 -Zc:wchar_t- -wd4251 -wd4275 -wd4290 -wd4675 -wd4786 -wd4800 -GR -EHa -I. -Ic:/libreoffice6.2_sdk/WINexample.out/inc-Ic:/libreoffice6.2_sdk/WINexample.out/inc/examples -I../../../include -Ic:/libreoffice6.2_sdk/WINexample.out/inc/complextoolbarcontrols -DWIN32 -DWNT -D_DLL -DCPPU_ENV=mscx -Foc:libreoffice6.2_sdkWINexample.outslocomplextoolbarcontrolsMyProtocolHandler.obj MyProtocolHandler.cxx
Оптимизирующий компилятор Microsoft (R) C/C++ версии 19.21.27702.2 для x64
(C) Корпорация Майкрософт (Microsoft Corporation). Все права защищены.

and the assembly will go, as a result of the assembly we get:

  • downloaded files in the directory C: libreoffice6.2_sdk WINexample.out inc,
  • manifest.xml file in C: libreoffice6.2_sdk WINexample.out misc complextoolbarcontrols complextoolbarcontrols META-INF,
  • complextoolbarcontrols.uno.dll in C: libreoffice6.2_sdk WINexample.out misc complextoolbarcontrols Windows,
  • file of components, links and description.xml in C: libreoffice6.2_sdk WINexample.out misc complextoolbarcontrols,
  • Objects in C: libreoffice6.2_sdk WINexample.out slo complextoolbarcontrols
  • and finally the extension complextoolbarcontrols.oxt itself in C: libreoffice6.2_sdk WINexample.out bin.

In essence, the Makefile does everything for us, in which we correctly entered the environment variables.

Cppmaker, based on the offapi.rdb and types.rdb registry files, downloads the dependencies needed to build cxx files.
The compiler collects these files into objects, linker hanging them from the LibreOffice directory collects the output dll,
then manifest.xml description.xml .components files are generated and all this is packaged together using zip into the .oxt archive.

From the version with cigwin (wiki) had to be abandoned due to the impossibility of assembly due to a hanging console.

To build under Linux you will need:

ibcurl4-openssl-dev zip git build-essential wget curl gstreamer1.0-libav libkrb5-dev nasm graphviz ccache libpython3-dev libreoffice-dev*

These packages do not take up much space, so we use the Docker image to build the extension.

The preparation process is almost similar to Window. Instead of setsdkenv_windows.bat, run setsdkenv_unix from / usr / lib / libreoffice / sdk.
After that, by analogy with Windows, go to / usr / lib / libreoffice / sdk / examples / cpp / complextoolbarcontrols and run make.
As a result, upon completion of the assembly, we will get the finished extension that lies in the directory specified during configuration through setsdkenv_unix.

Links that helped us:

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *