Here are several simple programs intended to demostrate how to use LibreOffice’s SDK API (https://api.libreoffice.org/) in C++. Some of the examples are translated from the official Java examples (https://api.libreoffice.org/examples/examples.html). All development and testing were conducted on the Ubuntu-22.04-x86_64 platform.
Build LibreOffice
The build process described below draws heavily from the official manual.
Note that, since Sept 22 2023, gcc/g++ must be at least version 12. sudo apt install gcc-12 g++-12 and then sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-12 60 --slave /usr/bin/g++ g++ /usr/bin/g++-12.
These are CMake instructions that add compile definations to libreoffice-sdk-example’s build which guarantee that examples are compiled with SDK accurately. Although I haven’t yet discerned their precise specifics, rest assured that they contribute to the correct compilation process.
These CMake variables define important paths and libraries needed for working with the LibreOffice SDK in a C++ project. Note that The default installation path for the SDK is /usr/lib/libreoffice/sdk/. However, it is necessary to manually compile LibreOffice and its SDK to ensure the correct functioning of some examples. We will configure our manually compiled LibreOffice SDK directory in the build.sh script.
This executes a cppumaker tool during the build process, which generates a C++ representation for IDL types. The -Gc flag indicates that only target files with modified content will be generated. The -O flag specifies the output directory, and ${PROJECT_SOURCE_DIR}/include is the destination directory. {SDK_PROGRAM_DIR}/types.rdb and ${SDK_PROGRAM_DIR}/types/offapi.rdb are the type libraries that cppumaker operates on.
Furthermore, the compilation and linking process requires some additional parameters, whose functions will be explained as needed.
Clone and building
git clone https://github.com/aniuzhong/libreoffice-sdk-examples.git
cd libreoffice-sdk-examples
./build.sh
LibreOffice SDK Examples for C++
Here are several simple programs intended to demostrate how to use LibreOffice’s SDK API (https://api.libreoffice.org/) in C++. Some of the examples are translated from the official Java examples (https://api.libreoffice.org/examples/examples.html). All development and testing were conducted on the
Ubuntu-22.04-x86_64 platform
.Build LibreOffice
The build process described below draws heavily from the official manual.
Build dependencies
Note that, since Sept 22 2023,
gcc/g++
must be at least version 12.sudo apt install gcc-12 g++-12
and thensudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-12 60 --slave /usr/bin/g++ g++ /usr/bin/g++-12
.Clone and building
Build examples
Requirements
In this project, I migrated the build system of core/odk/examples from make-based builds to the equivalent CMake.
These are CMake instructions that add compile definations to libreoffice-sdk-example’s build which guarantee that examples are compiled with SDK accurately. Although I haven’t yet discerned their precise specifics, rest assured that they contribute to the correct compilation process.
These CMake variables define important paths and libraries needed for working with the LibreOffice SDK in a C++ project. Note that The default installation path for the SDK is /usr/lib/libreoffice/sdk/. However, it is necessary to manually compile LibreOffice and its SDK to ensure the correct functioning of some examples. We will configure our manually compiled LibreOffice SDK directory in the build.sh script.
This executes a cppumaker tool during the build process, which generates a C++ representation for IDL types. The
-Gc
flag indicates that only target files with modified content will be generated. The-O
flag specifies the output directory, and${PROJECT_SOURCE_DIR}/include
is the destination directory.{SDK_PROGRAM_DIR}/types.rdb
and${SDK_PROGRAM_DIR}/types/offapi.rdb
are the type libraries that cppumaker operates on.Furthermore, the compilation and linking process requires some additional parameters, whose functions will be explained as needed.
Clone and building